Linq 到 NHibernate +转变+期货
我知道您可以通过调用 .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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它看起来像一个错误。如果您可以创建一个简单的重现测试用例,请在 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.