NHibernate-无需映射即可加入 [英] NHibernate - join without mapping

查看:89
本文介绍了NHibernate-无需映射即可加入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在没有指定映射的情况下加入两个类(使用Criteria API)?

Is it possible to join two classes without specified mapping between them (using Criteria API)?

我必须加入两个类并从这两个类中检索数据,但是我无法映射它们.我只知道第一类的外键 SomeID 和第二类的主键 ID .

I must join two classes and retrieve data from both but I can't mapping them. I know only foreign key SomeID in the first class and primary key ID in second.

如何创建加入他们的条件?没有映射就可以吗?

How to create Criteria to join them? Is it possible without mapping?

请帮忙,我真的很需要它,但我被卡住了. :/

Please, help, I'm really need it but I'm stuck. :/

PS

我知道'any'映射,但是我有10个字段,例如SomeID.仅为创建联接而为10个字段创建任何映射都是过分的. 如果没有其他解决方案,我会解决,但我不想这么做.

I know 'any' mapping but I have 10 fields like SomeID. Creating any mappings for 10 fields only for creating joins is overkill. If there is no other resolution I'll do it but I don't want to.

推荐答案

我不知道标准版本,但是在HQL中,您可以这样做:

I don't know the criteria version, but in HQL you can do it like this:

select customer, order from Customer customer, Order order 
    where order.CustomerID = customer.Id
    and customer.Id = 42

然后,结果集将是object []的列表,在该列表中,客户将被重复乘以其下达的订单数(当然,假设有很多订单中有一位客户).

The result set will then be a list of object[] where the customer will be repeated times the number of orders he has placed (assuming of course that there is one customer to many orders).

请注意,如果没有任何订单,结果将为空.

Please note that the result will be empty if there aren't any ordes.

这篇关于NHibernate-无需映射即可加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆