Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate - Where ISession.Query<T>() is located

Tags:


When I try to compile the following code

using System; using System.Collections.Generic; using System.Reflection; using System.Linq; using NHibernate;  namespace NewNHTest {     class A     { }      class Program     {         static void Main(string[] args)         {             ISession session;             var q = session.Query<A>();         }     } } 

I get the following error:

'NHibernate.ISession' does not contain a definition for 'Query' and no extension method 'Query' accepting a first argument of type 'NHibernate.ISession' could be found (are you missing a using directive or an assembly reference?) 

NHibernate.dll version is 3.0.0.4000.
The .Net version of project is 3.5.

What am I doing wrong?
Thank you for your help!

like image 372
StuffHappens Avatar asked Jan 12 '11 08:01

StuffHappens


People also ask

How do I get SQL query from NHibernate?

Translating NHibernate LINQ expression tree to SQL without executing query against database server is trick we can use to investigate generated SQL when writing complex queries. I'm using ToSql() extension method also when optimizing slow queries to find out what was actually generated by NHibernate.

How do I write a query in NHibernate?

Simple LINQ Queries are treated as NHibernate queries, but you have to connect them to repositories. Connect entities with Repository and IRepository to reduce its complexities. And it will be more structured. Let me know if I have taken you to right track or not.

What is Session factory in NHibernate?

Abstract factory pattern: SessionFactory Interface. The NHibernate framework uses the abstract factory pattern for creating sessions and using them to persist the objects into the database. It is a factory class that is used in an aspx page to create session objects.

What is NHibernate dialect?

The dialect property specifies a dialect class that NHibernate uses to build SQL syntax specific to a Relational Database Management System (RDBMS). We're using the Microsoft SQL 2012 dialect. Additionally, most dialects set intelligent defaults for other NHibernate properties, such as connection.


1 Answers

ISession.Query 

is new to NHibernate 3 and is an extension method. Try

using NHibernate.Linq 

and it should be resolved fine.

like image 139
Stephan Schinkel Avatar answered Oct 02 '22 12:10

Stephan Schinkel