Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate - join without mapping

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

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

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.

like image 895
dariol Avatar asked Apr 19 '26 03:04

dariol


1 Answers

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

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.

like image 147
mookid8000 Avatar answered Apr 21 '26 21:04

mookid8000



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!