我正在尝试将List<string>
传递给将接受它的方法,并使用它来创建要在实体框架查询中使用的include语句列表。
例如:
List<string> myIncludes = new List<string>();
myIncludes.Add("myObject.FirstRelatedObject");
myIncludes.Add("myObject.SecondRelatedObject");
我想使用此列表来获得类似以下内容的内容:dyamically:
var myQry = objectContext.object.Include(myIncludes[0]).Include(myIncludes[1]);
我该怎么做呢?我使用predicateBuilder来生成语句的“where”部分,但我认为这与“Include”部分不同。
答案 0 :(得分:5)
您可以尝试这样的事情(其中谓词是您的PredicateBuilder):
var includes = new List<string>() { "Include1, Include2" };
var query = this.Context.Campos;
foreach(var s in includes)
query.Include(s);
var result = query.Where(predicate.Expand());