Im trying to build a web app and want to employ an architecture that fully embraces separation of concerns. Im pretty new to the whole thing and im stumbling at the first hurdle, namely data access. I have an existing database so ive used the edmx wizard
to generate my entities ditrectly from the DB. this gives me a model.context.cs file like this
public partial class DBEntities : DbContext
{
public DBEntities()
: base("name=DBEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<AdminMenu> AdminMenus { get; set; }
public DbSet<Agency> Agencies { get; set; }
public DbSet<AgencyAdmin> AgencyAdmins { get; set; }
public DbSet<AgencyAgencyAssociation> AgencyAgencyAssociations { get; set; }
public DbSet<AgencyCommissionSplit> AgencyCommissionSplits { get; set; }
.....
.....
.....
etc , etc... all other db entities
}
so I have my dbcontext already created for me, I cant find any examples at all that implement an IRepository and IUnit of work where the context was generated from the db using the tt creator. Im totally confused and have spent several days just trying
to get my head around this. Should I be creating my own dbcontext generator and not use the tt generator ? Whats the best way to proceeed ? Am I even going about this the correct way ? help !
misuk11
Participant
1608 Points
1282 Posts
EF 5 unit of work and IRepository
Feb 16, 2013 05:35 PM|LINK
Im trying to build a web app and want to employ an architecture that fully embraces separation of concerns. Im pretty new to the whole thing and im stumbling at the first hurdle, namely data access. I have an existing database so ive used the edmx wizard to generate my entities ditrectly from the DB. this gives me a model.context.cs file like this
public partial class DBEntities : DbContext { public DBEntities() : base("name=DBEntities") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { throw new UnintentionalCodeFirstException(); } public DbSet<AdminMenu> AdminMenus { get; set; } public DbSet<Agency> Agencies { get; set; } public DbSet<AgencyAdmin> AgencyAdmins { get; set; } public DbSet<AgencyAgencyAssociation> AgencyAgencyAssociations { get; set; } public DbSet<AgencyCommissionSplit> AgencyCommissionSplits { get; set; } ..... ..... ..... etc , etc... all other db entities }so I have my dbcontext already created for me, I cant find any examples at all that implement an IRepository and IUnit of work where the context was generated from the db using the tt creator. Im totally confused and have spent several days just trying to get my head around this. Should I be creating my own dbcontext generator and not use the tt generator ? Whats the best way to proceeed ? Am I even going about this the correct way ? help !
Pengzhen Son...
Star
8624 Points
883 Posts
Microsoft
Re: EF 5 unit of work and IRepository
Feb 18, 2013 09:40 AM|LINK
Hi,
Please refer here
http://stackoverflow.com/questions/13793543/repository-pattern-mvc4-ef5
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
Hope it can help you.
Feedback to us
Develop and promote your apps in Windows Store