Generated SQL with PredicateBuilder, LINQPad and operator ANY

一笑奈何 提交于 2019-12-01 11:14:01

As you're using LINQKit, you can make this work by calling Compile() on the expression that feeds the EntitySet, and then calling AsExpandable() on the main query:

var predProduct = PredicateBuilder.True<Product>();
var predColorLanguage = PredicateBuilder.True<ColorLanguage>();

predProduct = predProduct.And(p => p.IsComplete);

predColorLanguage = predColorLanguage.And (
  c => c.IdColorEntity.Products.Any(predProduct.Compile()));

ColorLanguages.AsExpandable().Where(predColorLanguage).Dump();

As explained in the LINQKit article, the Compile method never actually runs: AsExpandable strips it out and modifies the expression tree so that it works with LINQ to SQL.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!