无法在 Linq 2 NHibernate 中投影实体
我正在 .Net 项目中使用 NHibernate 2,并且使用 Linq2NHibernate 提供程序。 这个简单的查询
var result = from d in session.Linq<Document>()
where d.CreationYear == 2010
select d.ChildEntity).ToList();
抛出一个异常,告诉我不可能将 ChildEntity 类型转换为 Document 类型。 这是为什么? 我还尝试将其翻译为查询方法,难道
session.Linq<Document>()
.where(d=>d.CreationYear == 2010)
.select(d=>d.ChildEntity)
.ToList();
选择方法不应该将 IQueryble 投影到 IQueryble 中,成为 TResult!=T 吗?
I'm working with NHibernate 2 in a .Net project and I'm using the Linq2NHibernate provider.
This simple query
var result = from d in session.Linq<Document>()
where d.CreationYear == 2010
select d.ChildEntity).ToList();
throws an exception telling me that is impossible to cast ChildEntity type do Document type.
Why is that?
I also tried to translate it in query methods, having
session.Linq<Document>()
.where(d=>d.CreationYear == 2010)
.select(d=>d.ChildEntity)
.ToList();
Isn't the select method supposed to project an IQueryble into a IQueryble, beeing TResult!=T ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
是的,这可能看起来很愚蠢,但是当您尝试仅选择一个对象时,linq2nhibernate 有时表现得很奇怪。
Try this:
Yes, this could look quite stupid, but linq2nhibernate sometimes behave very strange, when you try to select just an object.
旧的 Linq 提供程序极其有限,并且已经多年无人维护。
我建议您升级到最新的稳定版 NHibernate (3.2),它具有更好(且集成)的 Linq 提供程序。
The old Linq provider is extremely limited and has been unmaintained for several years.
I suggest that you upgrade to the latest stable NHibernate (3.2), which has a much better (and integrated) Linq provider.
你能试试这个吗:
can you try this: