NHibernate 使用条件连接多个子类和重复列名
假设我们有这样的实体结构:
Document
- DocumentA
- DocumentB
在基类 Document 中,我们有字段 Id、Name、CreateDate。在连接的子类 DocumentA 中,我们有字段 Book、Pages。在 DocumentB 中,我们有杂志、页面。
所以问题是当我尝试使用 Criteria 获取记录时:
var prj = Projections.ProjectionList();
foreach (var col in selectColumns)
{
prj.Add(Projections.Property(col), col);
}
criteria.SetProjection(prj).SetResultTransformer(new AliasToBeanResultTransformer(entityType));
因此,如果我们在 selectColumns 中有两个 Pages 列,NHibernate 将只从第一个列中选择数据。事实上,它甚至生成这样的 SQL 查询
SELECT top 15
this_1_.Pages as y0_
, this_1_.Pages as y1_
, this_.CreationDate as y2_
, this_.CreationAuthor as y3_
, this_.Name as y4_
, this_.Id as y5_
FROM Document this_
left outer join DocumentA this_1_ on this_.Id=this_1_.Id
left outer join DocumentB this_2_ on this_.Id=this_2_.Id
有谁知道如何使用 Criteria 解决我的问题?顺便说一句,我没有选择更改此结构,在这个系统中用户可以定义自己的类和嵌套类。
Assume we have this entity structure:
Document
- DocumentA
- DocumentB
In base class Document we have fields Id, Name, CreateDate. In joined subclass DocumentA we have fields Book, Pages. And in DocumentB we have Magazine, Pages.
So the problem is when i try to get records with Criteria:
var prj = Projections.ProjectionList();
foreach (var col in selectColumns)
{
prj.Add(Projections.Property(col), col);
}
criteria.SetProjection(prj).SetResultTransformer(new AliasToBeanResultTransformer(entityType));
So if we have in selectColumns two Pages columns NHibernate will only select data from first one. In fact it even generates SQL query like this
SELECT top 15
this_1_.Pages as y0_
, this_1_.Pages as y1_
, this_.CreationDate as y2_
, this_.CreationAuthor as y3_
, this_.Name as y4_
, this_.Id as y5_
FROM Document this_
left outer join DocumentA this_1_ on this_.Id=this_1_.Id
left outer join DocumentB this_2_ on this_.Id=this_2_.Id
Does anyone know how to solve my problem using Criteria? BTW I do not have option to change this structure, in this system user can define his own classes and nested classes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论