使用Entity Framework,您可以轻松地从数据库中获取数据,如下所示:
var allBooks = BookContext.Books;
因此,此代码会返回" Book"表
但是我收到的字符串告诉了我" table"我需要来自的数据。所以我有这样的事情:
public void GetData(string entity) // entity = "Book"
{
// Get data using the "entity" string from BookContext
BookContext.FromString(entity); // for exmaple
}
有没有办法使用字符串从BookContext
检索数据?
答案 0 :(得分:0)
快速查看source code of EF7表明,与之前的版本相比,Set(Type entityType)
类中没有任何DbContext
方法。只有它的通用版本Set<TEntity>()
。
所以我认为,如果不使用某些模糊的反射,就不可能。 (模糊,因为EF7没有DbSet
类的任何非泛型版本,这使得使用反射获得的集合非常困难)