Criteria.DISTINCT_ROOT_ENTITY vs Projections.distinct

While similar names, the usage is different. I. Projections.distinct(Projections.property(“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(Projections.property(“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 http://blog.fearofaflatplanet.me.uk/mvcminiprofiler-and-nhibernate-take-2 gist https://gist.github.com/1110153 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.

What is a Projection?

Projection is one of the basic operations of Relational Algebra. It takes a relation and a (possibly empty) list of attributes of that relation as input. It outputs a relation containing only the specified list of attributes with duplicate tuples removed. In other words the output must also be a relation. Example, if the relation … Read more