ADO.NET 用户首次尝试 EF。我正在尝试从表名字符串中获取一个表。
比我想象的还要难。
基本上我在这里:
var tableName = "Name.Entities.Measure" + measureType;
var table = Activator.CreateInstance("Name.Entities", tableName);
var unwrapped = table.Unwrap();
var type = unwrapped.GetType();
var dbset = context.Set<type>();
OR
switch (tableString)
{
case "table1":
return GetDataFromTable1();
case "table2":
return GetDataFromTable2();
}
代码越少越好;)
考虑创建一个具有所有实体的可搜索集合的扩展方法。
有人有更好的解决方案吗?
我一直在寻找同样的东西。尝试 Set() 的非通用版本:
var tableName = "Name.Entities.Measure" + measureType;
var type = Type.GetType(tableName);
var dbset = Context.Set(type);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)