【发布时间】:2016-03-05 00:19:15
【问题描述】:
criteria.CreateAlias("ChildObject", "c");
IProjection fullProjection = Projections.ProjectionList()
.Add(Projections.Property("Item"), "Item")
.Add(Projections.Property("c.SubItem"), "ChildObject.SubItem")
这个Object有属性Item和ChildObject。
ChildObject 有一个属性SubItem。
NHibernate 可以使用此投影成功查询并列出所有带有 ChildObject 的 Objects。
但是,ChildObject 在某些行上可以为空。这个投影似乎完全跳过了它们。他们从来没有到过我的变形金刚。我认为 NHibernate 会根据要求做出这些预测,以免在标准中为空。
所以我虽然可以通过以下方式胜过它:
Projections.Conditional(Restrictions.Eq("ChildObject", null), nullProjection, fullProection)
nullProjection 根本没有投影 ChildObject,但它只是抱怨 ....
Both true and false projections must return the same types.
有没有办法做这个投影并获得可为空的值?还是我必须做两个单独的查询?
【问题讨论】:
标签: c# nhibernate fluent-nhibernate