创建一个DbSet< T>.动态地在实体框架中? [英] Create a DbSet<T> dynamically in Entity Framework?
本文介绍了创建一个DbSet< T>.动态地在实体框架中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在LINQ to SQL中,我可以使用DataContext.GetTable<T>
动态创建存储库.除了在特定的DbContext
上声明属性以外,是否在Entity Framework 4中有类似的方法来执行此操作?例如:
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>();
这篇关于创建一个DbSet< T>.动态地在实体框架中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文