Linq 到 NHibernate +转变+期货

发布于 2024-12-14 11:50:08 字数 671 浏览 4 评论 0原文

我知道您可以通过调用 .ToFuture<>() 扩展方法来执行 Linq to NHibernate 查询。不过,我没有加载映射实体,而是直接将数据加载到 DTO 中。所以你会得到这样的信息:

var results = (from e in session.Query<Entity>()
               where e.Reference.Id == someId
               orderby e.Name
               select new Dto
               {
                   Id = e.Id,
                   Name = e.Name,
                   // ...
               }).ToFuture<Dto>();

这并不像我想要的那样工作(我敢说预期)。我现在收到错误:值“System.Object[]”不是“Entity”类型,不能在此通用集合中使用。如果我删除 .ToFuture() code> 它确实有效,但查询不是批处理的。

我知道您可以使用 QueryOver API 来完成此操作,我只是更喜欢 Linq to NH,因为它的代码非常干净。

I know you can execute a Linq to NHibernate query as a future by calling the .ToFuture<>() extension method. However I'm not loading mapped entities but directly loading the data into DTO's. So you get something like:

var results = (from e in session.Query<Entity>()
               where e.Reference.Id == someId
               orderby e.Name
               select new Dto
               {
                   Id = e.Id,
                   Name = e.Name,
                   // ...
               }).ToFuture<Dto>();

This doesn't work as I want it (I dare to say expected). I now get an error: The value "System.Object[]" is not of type "Entity" and cannot be used in this generic collection. If I remove .ToFuture() it does work, but the query is not batched.

I know you can do this with the QueryOver API, I just like Linq to NH better because it's so much cleaner code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

行雁书 2024-12-21 11:50:08

它看起来像一个错误。如果您可以创建一个简单的重现测试用例,请在 https://nhibernate.jira.com/。

在执行此操作之前,请验证您是否使用的是最新版本(当时为 3.2),因为已经存在 类似缺陷已在此版本中修复。

It looks like a bug. If you can create a simple reproduction test case, please enter a new issue at https://nhibernate.jira.com/.

Before doing that, please verify if you're using the latest version (3.2 at the time), as there was already a similar defect that was fixed in this release.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文