Hello everybody,

this is my first post in this group and I wonder if anybody has
experienced this same problem.

I'm working on a NHibernate-based project and I wanted to play a
little with Linq to NHibernate, from NHibernate Contrib.

So I happily integrated it in my system and turned some existing Hql
queries into Linq expressions.
Just as a simplified example: let's say that I had this function...

IEnumerable<User> GetUsers(ISession Session, long SiteId)
{
    return Session.CreateQuery(@"
select User
from User User
where User.Site.Id = :SiteId
")
        .SetInt64(":SiteId")
        .Enumerable<User>();
}

What I did is to turn it in this form:

IEnumerable<User> GetUsers(ISession Session, long SiteId)
{
    return
        from User in Session.Linq<User>()
        where User.Site.Id = SiteId
        select User;
}

In order to check that everything was ok, I turned on Sql Profiler to
examine the generated Sql query.

Here I noticed that query lacked an important optimization that is
normally present when you create a query using Hql.

In the first case the generated Sql query contains no join between
User and Site and the expression [UserClient.Site.Id] is replaced
(roughly) by [USER.SITE_FK].

In the second, sadly, no optimization and a nasty and useless join.

This example is a simplified version of my real case, in which I had 3
joins completely without purpose!

I went through the code of Linq to NHibernate and I realized what
maybe you all already know, that is that it is implemented using the
ICriteria objects. Now, from further tests, it seems to me that it's
the Criteria system that lacks this optimization: every reference to
related entities, even just to retrieve the id, lead to a join.

Does anybody of you have thoughts to share about this?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to