我必须从任意表中动态选择:
IEnumerable<object> table = typeof(MyContext).GetProperty(tblName).GetValue(context, null) as IEnumerable<object>;
但现在还有一个问题,我似乎无法找到include
相关实体进入上方动态table
的方法:
string relations= "relatedentity1,relatedentity2,relatedentity3"
relatedEntities = relations.Split(',');
foreach (string relatedEntity in relatedEntities)
{
(table as ObjectQuery<object>).Include(relatedEntity); // error line
}
这种方法给我这个错误(table
对象不是null
):
Object reference not set to an instance of an object.
通常,这就是它的完成方式:
MaterialStartingBalance = (from a in context.MaterialStartingBalance
.Include("Warehouse")
.Include("Account")
.Include("Material")
.Include("SalesOrder")
select a).ToList();
我如何实现这一目标?非常感谢!