我有一个很好的编译查询.我传递了一个product_id,它返回该产品的产品评论信息.
from cat in ctx.cat_table join prod in ctx.prod_table on cat.category_id equals prod.category_id select new { cat_id = cat.category_id,prod_id = prod.product_id,name = prod.product_name,descript = prod.product_description,price = prod.price,reviews = (from mcq in mycompiledquery(ctx,prod.product_id) select new { rating = mcq.review_rating,review = mcq.review_text } }
The LINQ expression node type ‘Invoke’ is not supported in LINQ to Entities
我想到的一个替代方案是用sql视图替换我编译的查询,但我担心会出现负面的性能损失.
非常感谢您提供的任何建议.
解决方法
您可以在其他查询中使用编译查询,但不能使其依赖于外部查询.例子
// You can do var someParams = 10; var dataQuery = from x in ctx.someData join y in myCompiledQuery.Invoke(ctx,someParams) on x.Id equals y.Id where x.Name = "ABC" select new { x,y }; // You can't do - this example will not compile but let's use it for description var dataQuery = from x in ctx.someData join y in myCompiledQuery.Invoke(ctx,x.someParams) on x.Id equals y.Id where x.Name = "ABC" select new { x,y };
区别在于第一个示例只执行委托(编译的查询是委托)并返回IQueryable.第二个示例无法执行委托,因为它依赖于外部查询数据,因此它将其作为必须添加到表达式树并在查询执行期间得到的东西.这会失败,因为EF提供程序无法转换委托调用.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。