Reputation: 1739
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.
Upvotes: 17
Views: 12872
Reputation: 6654
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.
Upvotes: 34
Reputation: 8381
There is no new syntax. Linq is still linq. The method named Linq in the old provider is named Query in the new one.
Instead of new List(enumerable) you can use enumerable.ToList() to prevent loading every object in the list with a separate sql query.
Upvotes: 3