指定要包含在动态IEnumerable <object> results </object>中的相关对象

时间:2014-11-17 12:18:28

标签: c# linq entity-framework dynamic

我必须从任意表中动态选择:

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();

我如何实现这一目标?非常感谢!

0 个答案:

没有答案