问题描述
在 LINQ to SQL 中,我可以使用 DataContext.GetTable
In LINQ to SQL, I can create a repository dynamically using DataContext.GetTable<T>. Is there a similar way to do this in Entity Framework 4 other than declaring the properties on the specific DbContext? For example:
public MyDbContext: DbContext { public DbSet<MySet> MySets {get; set;} }
我想知道如何像使用 LINQ to SQL 那样动态创建/获取对 MySets 的引用:
I would like to know how can I create/get a reference to MySets dynamically as I can with LINQ to SQL as in:
var mySet = MyDbContext.GetTable<MySet>();
推荐答案
DbContext 对此有方法:
var set = context.Set<MyEntity>();