NHibernate 3.0: No FirstOrDefault() with QueryOver?

I have now found out that I could use the Take() extension method on the IQueryOver instance, and only the enumerate to a list, like so: Result precedingOrMatchingResult = Session.QueryOver<Result>(). Where(r => r.TimeStamp < timeStamp). OrderBy(r => r.TimeStamp).Desc. Take(1).List(). //enumerate only on element of the sequence! FirstOrDefault(); //get the preceding or matching result, if there … Read more

Eagerly fetch multiple collection properties (using QueryOver/Linq)?

I prefer to use the linq provider if at all possible especially if you are using newer versions of nhibernate (>= 4.0). As long as you have your collections mapped as ISets (requires .net framework >= 4) which we converted to such that we could do eager loading and avoid cartesian products. I feel like … Read more

queryover and (x like ‘a’ or y like ‘a’)

You could use the NHibernate Disjunction class to do this in a more elegant (IMHO) fashion: var disjunction= new Disjunction(); disjunction.Add(Restrictions.On<Type>(e => e.Code).IsLike(codePart)); disjunction.Add(Restrictions.On<Type>(e => e.Description).IsLike(codePart)); //(and so on) and then: query.Where(disjunction) Each “OR” is a separate instruction, which helps if you want to add the predicates conditionally.

What is the difference between JoinQueryOver and JoinAlias?

Functionally they do the same thing, create a join to another entity. The only difference is what they return. JoinQueryOver returns a new QueryOver with the current entity being the entity joined, while JoinAlias returns the original QueryOver that has the current entity as the original root entity. Whichever one you use is a matter … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)