![](/img/trans.png)
[英]How to use expressions to build a LINQ query dynamically when using an interface to get the column name?
[英]How to load objects dynamically to a query using LINQ expressions?
我正在嘗試編寫一個函數以動態地將對象包括到查詢中。
目的是使用像
empresa.Get(x => x.Employees);
要么
empresa.Get(x => x.Employees, x => x.Department);
但是當我嘗試這樣做時,我收到此錯誤:
無法將lambda表達式轉換為Expression <Func <EmpresaModel,object >> []類型,因為它不是委托類型。
我寫的功能如下
public IQueryable<EmpresaModel> Get(params Expression<Func<EmpresaModel, object>>[] includes)
{
var query = _conexao.Set<EmpresaModel>();
foreach (var property in includes)
{
query.Include(property);
}
return query;
}
我該如何解決?
您必須在類中包括System.Linq.Expressions
引用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.