是否可以從列表中指定「包含」?Linq從列表中包含<string>
我有可能的子表列表將包含在:
List<string> includedTables
我現在的數據庫調用看起來是這樣的:
return db.SA_Items
.Where(x => x.LastUpdated > lastUpdated)
.Where(x => x.Active == true)
.OrderBy(x => x.ItemID)
.Skip(offset)
.Take(limit)
.ToList();
我會以某種方式在列表中的foreach串並在數據庫調用中添加.Include(....)
...
例如,如果列表中有2個字符串,則代碼將與此等效:
return db.SA_Items
.Include("first string in the list")
.Include("second string in the list")
.Where(x => x.LastUpdated > lastUpdated)
.Where(x => x.Active == true)
.OrderBy(x => x.ItemID)
.Skip(offset)
.Take(limit)
.ToList();
List也可能爲空。
是否可以動態地做到這一點?
任何人都可以給我任何指針嗎?
@Fabjan,就必須要急於負載相關的實體,即提出Include'方法 – octavioccl