管道和过滤器以及 CompiledQuery.Compile
我已经开始使用 linq to sql 和实体框架,并且发现开发体验相当不错。就像您可以分解查询并组合不同查询的方式非常好 - 请参阅管道和过滤器。
但我发现的问题是,如果我使用编译查询,性能可以大大提高(在我的例子中大约是 4 倍,这是我不能忽略的)。但我发现编译查询的问题是他们不喜欢使用 IQueryable...
有谁知道我如何克服这个缺点???我的工作方式是编译查询只是引用使用 IQueryable 的其他查询,这样我就可以切换使用或不使用编译查询。但据我发现,这效果不太好。
有什么想法吗?
干杯 安东尼
I have started using linq to sql and the entity framework and have found the development experience to be fairly good. Like the way you can break a query apart and combine different queries is quite nice - see pipes and filters.
But the problem that I have found is that performance can be greatly increased (in my case by a factor of about 4 which I can't ignore) if I use complied queries. But the problem I have found with compiled quires is that they don't like working with IQueryable...
Does anyone have any ideas on how I can get round this shortcoming??? The way I was working is that the Compiled Query just referenced other queries that used IQueryable, that way I could switch in and out of using compiled quires or not. But as I have found out this doesn't work so well.
Any ideas?
Cheers
Anthony
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不可以,您不能将 CompiledQuery 的结果与另一个 IQueryable 组合起来。请记住,CompiledQuery 的唯一目的是缓存将 IQueryable 转换为实体框架规范命令树的结果。如果您可以将其与另一个 IQueryable 组合,则需要重新编译它才能执行,这完全违背了 CompiledQuery 的目的。
No, you cannot compose the results of CompiledQuery with another IQueryable. Remember, the sole purpose of CompiledQuery is to cache the results of transforming an IQueryable into an Entity Framework canonical command tree. If you could then compose this with another IQueryable, then it would need to be recompiled for execution, which completely defeats the purpose of CompiledQuery.