Linq to NHibernate Progress Report

Another sprint finished (although with the amount of other stuff I've been doing lately, a "crawl" may be a better description), so time for brief update.

This one doesn't really add any visible functional improvements, rather I've been concentrating on improving the interaction between the Linq provider and the NHibernate core. So what has changed? Firstly, the Linq expressions now tie into the NHibernate HQL Query cache correctly. So running a query for the second (and subsequent) time results in a cache hit for the NH query plan, resulting in considerably less processing taking place prior to us actually hitting the database.

Secondly, and vital for the first to be useful, automatic parameterisation of queries now takes place. By this, I mean that a query such as:

from c in Customers where c.Address.City = "London"

now generates HQL of:

select c from Customers c where c.Address.City = :p1

which in turn generates parameterised SQL that gets cached within the database (at least, it does for SQL Server)

Hence, a subsequent query of

from c in Customers where c.Address.City = "Madrid"

will result in cache hits right through the chain, and so should give great performance. Back to getting more queries working tomorrow.


Comments

# Social comments and analytics for this post
Gravatar This post was mentioned on Twitter by srstrong: Just posted a brief Linq to NH update http://bit.ly/27448i Nothing earth-shattering here (luckily, I guess!), but still making progress
Left by uberVU - social comments on 10/23/2009 5:45 AM
# Reflective Perspective - Chris Alcock » The Morning Brew #461
Gravatar Reflective Perspective - Chris Alcock » The Morning Brew #461
Left by Pingback/TrackBack on 10/23/2009 9:38 AM
# re: Linq to NHibernate Progress Report
Gravatar Awesome, really digging it..
Left by Kenny Eliasson on 10/23/2009 10:02 AM
# re: Linq to NHibernate Progress Report
Gravatar Just a random though -> will your linq to sql be able to handle custom functions (like ayende.com/.../...bernate-The-really-easy-way.aspx)?
This is probably way out of scope for where you're trying to get to doing, but being able to do define custom functions on the provider, then call them via LINQ would probably make a few people cream their pants.
Left by David Kemp on 10/23/2009 11:11 AM
# re: Linq to NHibernate Progress Report
Gravatar David,

Out of scope for the first release, but definitely on my list of "things that would be cool" once the core provider is done
Left by sstrong on 10/23/2009 1:21 PM
# re: Linq to NHibernate Progress Report
Gravatar Cool. Did you ever measure the time it takes to convert LINQ to HQL vs. HQL to SQL? I understand now the latter is cached. How much performance would it buy to start caching from the IQueryable tree?

I think this can be done pretty transparently in re-linq, we just have to prioritize it.
Left by Stefan Wenig on 10/23/2009 1:40 PM
# re: Linq to NHibernate Progress Report
Gravatar Stefan,

I haven't done any actual timings, that level of optimisation isn't high on my TODO list! But the caching seemed like an obvious thing to get in place since for sure the HQL to SQL conversion is fairly expensive. I'm already caching based on the IQueryable tree rather than the QueryModel, so baring some micro-optimisations I think it's about as good as it can get.
Left by sstrong on 10/23/2009 1:50 PM
# re: Linq to NHibernate Progress Report
Gravatar Good work!
Where can i report error that:
if same classes (persistant) impelemt interface TInter (with Prop property) and later when i make this:
class Repository<T> where T:TInter
...
public IEnumerable<T> Find() {
session.Linq<T>().Where(i => i.Prop);
}

When i fire this linq i got error :)
Left by Kamil on 10/24/2009 1:02 AM
# re: Linq to NHibernate Progress Report
Gravatar Good work. Do you have a GIT or open SVN repository to view work in progress?
Left by Matt Freeman on 10/24/2009 10:04 AM
# re: Linq to NHibernate Progress Report
Gravatar Steve--

Do you have a certain date/timeframe in mind for release of the HQL provider..? The current Linq Nhibernate provider is killing me; it gets the job done but...

Really looking forward to yours...
Left by --F on 10/25/2009 10:45 AM
# 
Gravatar Creating NHibernate Linq Query from arbitrary Criteria
Left by chadly.net on 10/30/2009 3:47 PM
# re: Linq to NHibernate Progress Report
Gravatar Kamil,

Best place to start would be to post on the NHUsers list
Left by sstrong on 11/4/2009 10:03 AM
# re: Linq to NHibernate Progress Report
Gravatar Matt,

Al the new Linq code is in the NH Trunk SVN repository, which can be found at nhibernate.svn.sourceforge.net/.../trunk/
Left by sstrong on 11/4/2009 10:06 AM
# re: Linq to NHibernate Progress Report
Gravatar F,

Timeframe is a bit tricky, but I'm really hoping that we're now talking weeks rather than months. I'll keep the blog posted as I make progress
Left by sstrong on 11/4/2009 10:07 AM
# re: Linq to NHibernate Progress Report
Gravatar We're looking forward in measuring your progress @ ORMBattle ;)

OpenAccess got additional 20% there during the last month; BLToolkit is also far beyond NH now... So I think it's right time to show something.
Left by Alex Yakunin on 11/5/2009 11:44 PM
# re: Linq to NHibernate Progress Report
Gravatar Is the LINQ provider going to support Future queries?
Left by Dmitry on 11/8/2009 12:26 AM
# re: Linq to NHibernate Progress Report
Gravatar Alex,

ORMBattle is about the last thing on my mind. I'll ship this when I'm good and ready, and I'll let the users decide if the performance, features etc are fit for purpose, rather than be driven by some benchmark.

All the very best, and keep up the good work.

Steve
Left by sstrong on 11/23/2009 4:57 PM
# re: Linq to NHibernate Progress Report
Gravatar Dmitry,

Yes, this should support Future queries. No tests yet to prove that, but in principle it should certainly be possible.
Left by sstrong on 11/23/2009 4:58 PM
# re: Linq to NHibernate Progress Report
Gravatar
I am a Chinese,my English very bad . I have a question.

there is a table:
create table Test(
ID int primary key identity(1,1) not null,
Name nvarchar(50) not null,
Recommend tinyint not null)

data:
ID Name Recommend
1 aa 3

in linq to sql,we can use:
XXDataContext.Test.Where(o=>(o.Recommend&1)==1).ToList();
there is nothing problem ,
but in linq to nhibernate:
session.Query<Test>().Where(o=>(o.Recommend&1)==1).ToList();
or
session.Linq<Test>().Where(o=>(o.Recommend&1)==1).ToList();
there is a exception (not supported).

must we use "session.CreateQuery("from Test o where (o.Recommend&1)=1").List<Test>();" ?

thanks!
Left by Question on 12/5/2009 11:47 AM
# re: Linq to NHibernate Progress Report
Gravatar Steve, haven't seen a post in a bit...how is it coming? Thanks for the hard work.

Eric
Left by Eric Swann on 12/11/2009 5:27 PM

Leave Your Comment

Title*
Name*
Email (never displayed)
 (will show your gravatar)
Url
Comment*

Please add 4 and 8 and type the answer here:

Preview Your Comment.