Specifying fetch strategy (select, join, etc) in nhibernate queryover query?

I know this isn't what you asked for, but worst case you can encapsulate your magic strings in a type safe way using different methodologies here: C# String enums.

Combining paging and eager fetching is tricky. If you specify fetch to select via Criteria API then each item in TrackPrices will be loaded in separate query - N+1 issue. You don't need bother with eager loading at all.

You can set batch size for TrackPrices in mapping to aleviate N+1 issue. There are some details about mixing eager fetching and paging in this article.

From the time I posted this question, I've managed to find a workaround / solution which others might find useful as well. Basically, in such case you must first create another query which distinctly selects the primary keys of the main query, together with pagination. Since the DISTINCT(ID) will return only the results you want, you can use the pagination of SQL without any problems.

Then, you re-run the main query, without pagination but using a condition where the ID is in one of the list returned. I created a general method which takes a criteria, looks up the IDs returned and adds them as a condition to the main criteria. Code below: public static void LimitCriteriaByPrimaryKeys(this NICriteria criteria, string primaryKeyName, int pageNum, int pageSize) { var session = NHManager.Instance.

GetCurrentSessionFromContext(); if (pageSize 0) { if (pageNum 0) { criteria. Add(Expression. In(pKeyIDName, ids)); //adds the primary key restriction var crit = criteria; crit.

SetResultTransformer(new NTransform. DistinctRootEntityResultTransformer()); } else { criteria. Add(Expression.

Eq(pKeyIDName, 0)); //this is added specifically so that the main criteria returns NO results criteria. Add(Expression. Eq(pKeyIDName, 1)); } } } The methods NHManager.Instance.

GetCurrentSessionFromContext(); can be replaced with your own method to retrieve the current session from the session factory. Hope it helps!

What about, I would go just as create repository as iqueryable with eager loading. After pagination done via linq query on iqueryable collection of lists. Where you use .

Take(x) – cpoDesign Jul 26 at 12:31 But then, I have to load all the collection itself from the database. If you have a lot of records, it is extremely wasteful and expensive, plus slow. – Karl Cassar Oct 13 at 10:18.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions