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!
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.
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.
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.
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.
ISession.Query
is new to NHibernate 3 and is an extension method. Try
using NHibernate.Linq
and it should be resolved fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With