I have the following database model:
Data <-- DataLanguage --> Language
In code I can access these like this:
Data.Languages
I want to do a eager load of these items on data status. The way I
would do that in SQL is this:
1st roundtrip: Fetch matching data items and the data language keys
SELECT data.*
FROM Data data
WHERE data.Status IN (2, 5)
SELECT languages.*
FROM DataLanguages languages
JOIN Data data ON languages.DataId = data.Id
WHERE data.Status IN (2, 5)
2nd roundtrip: Fetch all language
SELECT *
FROM Languages language
WHERE Id IN ( [The distinct from the language keys] )
Is this behavior somehow possible via the criteria API?
a. Using FetchMode.Select results in a seperate query for the
languages select query for each data item. Resulting in the language
data to be loaded unnecesary for each data item.
b. Using FetchMode.Eager results duplicate Data entries in the result
set which I thought NHibernate would autofilter but this after reading
the documentation not possible for Bags. I have not tried a Set yet
maybe that would work here. This does load all stuff in one query but
the dataset retrieved is very large.
c. Using FetchMode.Lazy results in a very lazy loaded set which is
ofcourse as you would expect. That is the reason why I am trying to
improve it for this specific scenario.
I'm currently using .SetFetchMode(FetchMode.Select) as it seems to
give the best performance but I would like it more efficient if that
is possible via the criteria api / nhibernate. If not, then I will
need to split up the criteria query in several queries.
Ramon
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.