![](/img/trans.png)
[英]Combining GetPropertyName + multiple params function (params keyword)
[英]how to read the parameter with params keyword and implementing a function
嗨,我这里有一个代码片段。 这不是我的,在学习如何处理Entity Framework
我在互联网上看到了这个,我知道它只包含(急于加载)导航属性,然后将其返回为IQueryable
我想知道的是:
您如何阅读此参数params System.Linq.Expressions.Expression<Func<T, object>>[] includeProperties
?
您如何调用或使用此功能? (应该通过收集,对吗?举个小例子会很有帮助,因为我在看一些演示时会以某种方式学习)
public IQueryable<Customer> AllIncluding(params System.Linq.Expressions.Expression<Func<T, object>>[] includeProperties) { var query = context.Customers; foreach (var includeProperty in includeProperties) { query = query.Include(includeProperty); } return query; }
任何帮助将非常感激。 谢谢!
params
使您可以将数组参数作为实际数组或值的开放式列表传递:
var includes = new Expression<Func<Customer, object>>[]
{
i => i.SubProperty1,
i => i.SubProperty2
};
var query = db.Entities.AllIncluding(includes);
要不就
var query = db.Entities.AllIncluding(i => i.SubProperty1, i => i.SubProperty2);
我正在猜测具体的类型和属性,但希望您能理解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.