Tradeoffs using NHibernate 3.0 QueryOver or LINQ provider

LINQ and QueryOver are completely different query methods, which are added to the ones that existed in NHibernate 2 (Criteria, HQL, SQL) QueryOver is meant as a strongly-typed version of Criteria, and supports mostly the same constructs, which are NHibernate-specific. LINQ is a “standard” query method, which means the client code can work on IQueryable … Read more

Criteria.DISTINCT_ROOT_ENTITY vs Projections.distinct

While similar names, the usage is different. I. Projections.distinct(“id”)); this statement would be translated into SQL Statement. It will be passed to DB Engine and executed as a SQL DISTINCT. See: 17.9. Projections, aggregation and grouping so e.g. this example: List results = session.createCriteria(Cat.class) .setProjection( Projections.projectionList() .add( Projections.distinct(“id”)) ) ) .list(); would seems like: SELECT … Read more

What is NHibernate?

NHibernate is an ORM, or Object-Relational Mapper. In the same line as LINQ to SQL, Entity Framework, LLBLGen, and others, ORM tools remove most of the need to write stored procedures to handle common data access (CRUD) for your business objects. ORM tools require that you create (either manually or with a visual designer…depends on … Read more

DTO naming conventions , modeling and inheritance

Recommendation is that you should just have one DTO class for each entity suffixed with DTO e.g. CustomerEntryDTO for the Customer entity (but you can certainly use inheritance hierarchies as per choice and requirements). Moreover, Add a abstract DTOBase kind of base class or an interface; and do not use such deep inheritance heirarchies for … Read more

Using MiniProfiler’s database profiling with NHibernate

[UPDATE] Please see the following links for a version of that uses RealProxy to proxy the SqlCommand – batching is now supported blog gist I’ve left the original answer unaltered as it was accepted. [/UPDATE] I’ve managed to partially get this to work by implementing a Profiled Client Driver (example for Sql Server … 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.