NHibernate Criteria 对内存中实体集合的查询
我想对内存中的集合应用条件查询 实体,而不是数据库。这可能吗? 让 Criteria API 像 LINQ 一样工作?或者,转换 Criteria 查询到 LINQ 查询。
谢谢!
I would like to apply a Criteria query to an in-memory collection
of entities, instead of on the database. Is this possible?
To have Criteria API work like LINQ? Or alternatively, convert
Criteria query to LINQ query.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不相信您可以使用 Criteria 来查询内存中的集合,并且仔细想想它似乎没有多大意义。如果我理解正确的话,您已经对数据库进行了查询。我建议调整您的原始查询(无论您选择哪种方法)以包含所有过滤器。或者您可以使用 LINQ(如您所建议的)来优化您的结果。
另外,您想要从内存中查询的理由是什么?
I don't believe you can use Criteria to query against an in-memory collection and come to think about it it doesn't seem to make much sense. If I'm understanding everything correctly you've already queried against your database. I'd suggest to either tune your original query (whichever method you choose) to include all of your filters. Or you could use LINQ (as you suggested) to refine your results.
Also, what's your reasoning for wanting to query from memory?
听起来您正在滚动自己的缓存机制。我强烈建议您查看 NHibernate 的二级缓存。它可以优雅地处理许多复杂的场景,例如使基础表更新时的查询结果无效。
http://ayende.com/Blog/archive /2009/04/24/nhibernate-2nd-level-cache.aspx
It sounds like you're rolling your own caching mechanism. I would highly recommend checking out NHibernate's 2nd level cache. It handles many complex scenarios gracefully such as invalidating query results on updates to the underlying tables.
http://ayende.com/Blog/archive/2009/04/24/nhibernate-2nd-level-cache.aspx