7

Ok, I think I have all my configurations right and now I am just trying to do a select query from the database selecting some data. Now I am using NHibernate 3.0 which I though by default support LINQ (or at least a good portion of link. Now every LINQ example I find has this code

session.Linq<User>()

but I for the life of me can't find how or where session is being set. Is this that proper why of doing in in 3.0 and if so how do I set sessions (what usings do I need, classes, methods, etc...)? If not, what is the proper way of using LINQ with NHibernate 3.0?

UPDATE:

Now I have the following code:

var configuration = new Configuration();
configuration.Configure();
configuration.AddAssembly(typeof(Tag).Assembly);
var sessionFactory = configuration.BuildSessionFactory();
var session = sessionFactory.GetCurrentSession();

but I get a compiler error saying that NHibernate.ISession does not have a definition for Linq. I have the follow usings:

using System.Collections.Generic;
using System.Web.Mvc;
using MyProject.Models;
using MyProject.ViewModels.Desktop;
using NHibernate.Cfg;

Am I missing something?

2
  • 1
    I believe it's session.Query<User>() in NHibernate 3 as the LINQ provider was brought into the core assembly Commented Jan 7, 2011 at 0:25
  • The NHibernate wiki is a good resource for getting started - nhforge.org/wikis/howtonh/… Commented Jan 7, 2011 at 0:27

2 Answers 2

8

You need to import the namespace:

using NHibernate.Linq;

Also, it's now:

session.Query<TEntity>();

instead of:

// Deprecated
session.Linq<TEntity>();
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I did figure out that I needed to use .Query instead of .Linq for NHibernate 3, Thanks
2

You get a session from the NHibernate SessionFactory.CreateSession() method. Once you have one, you can then use either HQL queries, the NH query API or LINQ to access the data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.