Linq – Nhibernate 3 & LINQ

linqnhibernate

I'm converting some code from Nhibernate 2.x to 3.0. Before, i was using the LINQ plugin, to get LINQ support. My understanding was that in 3.0 it got rolled in as a first class feature. So my question is, i used to have this:

return new List<T>(session.Linq<T>().Where(where));

What does that look like with the new syntax? i went through the nhib 3 docs and tutorial and didn't see anything about the linq stuff, so i couldn't find an example to pattern after.

Best Answer

In NHibernate 3 with Linq you do this:

from u in session.Query<User>()
where u.Username == username
select u

Or

session.Query<User>().Where(u => u.Username == username)

Not sure if this is what you're looking for.

EDIT: Query<T> is an extension method. Don't forget to add the using NHibernate.Linq to be able to use it.