且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何筛选子集合使用LINQ动态

更新时间:2023-01-29 20:48:02

方式你命名你的类/属性,很难猜到哪一个是一个单一的对象,哪一个是一个集合属性。

From the way you named your classes/properties it's hard to guess which one is a single object and which one is a collection property.

如果 ORDERS class属性 ORDER_DETAILS ORDER_DETAILS 类和 ORDER_DETAILS 类属性产品 产品类的类的 HEADINGS ,那么下面应该做的技巧:

If ORDERS class property ORDER_DETAILS is a collection of ORDER_DETAILS class, and ORDER_DETAILS class property PRODUCTS is a singe object of PRODUCTS class having a string property HEADINGS, then the following should do the trick:

.Where("ORDER_DETAILS.Any(PRODUCTS.HEADING.ToLower().Contains(\"foo\"))")

基本上与使用lambda参数的静态查询相同

It's basically the same as static query with lambda parameters skipped

.Where(o => o.ORDER_DETAILS.Any(d => d.PRODUCTS.HEADING.ToLower().Contains("foo")))