I have a problem trying the following with nHibernate:
- Eager loading.
- Use selects (here is my problem, I can only do this using joins)
- Filtering children.
Let's use an example where we have the RichPerson
class that can have multiple: cars, houses, motorbikes and companies. All mapped to different entities with different tables.
If I try the following:
session.CreateCriteria(typeof (RichPerson))
.Add(Expression.Eq("Id", someId))
.CreateCriteria("Cars")
.Add(Expression.Eq("Brand","Ferrari")
nHibernate will make an inner join in order to retrieve the Cars. If RichPerson some Ferrari cars, the join will send duplicated data.
Even with a .SetFetchMode("Cars",FetchMode.Select)
nHibernate does a join.
I guess the join is because I ask: the rich person with id X and with Ferrari cars. Thus, the join is needed. But I just want to preload (somehow) the Ferrari cars. And use them as guy.Cars
.
Uf! I don't know if I've expressed myself correctly. Anyway, thanks for your time reading this.