Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nhibernate 3 & LINQ

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.

like image 566
bryan costanich Avatar asked Feb 22 '11 19:02

bryan costanich


People also ask

What is the use of NHibernate?

NHibernate is an ORM (Object Relational Mapper). Its purpose is to map objects in your OO application to tables in a database for persistence. Why would you need it? Because it can save you from writing a lot of tedious ADO.NET code.

What is the latest version of NHibernate?

NHibernate 5.3 was released on July 19, 2020.

What is NHibernate in C #?

NHibernate is A tool that creates a "virtual representation" of database objects within the code. Used to solve the problem of impedance mismatch between Class and relational databases and tables.

Is NHibernate an ORM?

NHibernate is a popular, fast growing ORM with a helpful community of seasoned developers. Used in thousands of commercial and open source projects.


1 Answers

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.

like image 199
goenning Avatar answered Oct 14 '22 22:10

goenning