views:

447

answers:

4

I thought that the purpose of using Linq2Nibernate was to return IQueryable and build up an expression tree. I am not sure if this is correct or not.

Why would anyone use Linq2Nibernate if they are not going to return IQueryable?

What else would it be used for?

I would love some more input on this topic

Linq For Nhibernate

A: 

What's Linq2NHibernate? As there are several projects which tried to implement a linq provider for nhibernate but all stopped before reaching completion.

Any linq provider needs to return IQueryable, or better an IEnumerable as that's how linq works. It's convenient to return an IQueryable as you then can re-use existing code to pad additional operators to an already created query (as ctx.Employee which might return IQueryable is already a query)

Frans Bouma
+3  A: 

I'm planning to use NHibernate.Linq to replace my HQL and criteria API queries with LINQ expressions. In other words, I'll generate the query in code (as a LINQ expression) and then pass it to NHibernate.Linq and NHib to convert it into a database query.

FYI there is an alpha version available.

John Rayner
+1  A: 

I have planed to start using Linq2Nibernate but haven't got round to i yet.

My reason for wanting to user Linq2Nibernate is the nice syntax when constructing criterions and later querying them out.

Here is a nice simple example. http://ayende.com/Blog/archive/2007/03/16/Linq-for-NHibernate.aspx

Emil C
+1  A: 

I am using Linq2Nhibernate with my repository pattern that returns IQueryable objects. As you know, IQueryable is only a query definition - doesn't touch database yet.

Then local requirements are added to the query and finally the object or list is materialized.

Seems to work excellent and prevents unnecessary db queries for partial data at higher abstract layers.

twk