views:

78

answers:

1

Hi all

I have a object model a bit like this:

public class Foo
{
  public int Id {get;set;}
  public string FooName {get;set;}
}

public class Bar
{
  public int Id {get;set;}
  public Foo Foo {get;set;}
}

These correspond to tables in the database in the typical one-to-many kind of way.

Using Linq to NHibernate to query Bars according to their Foo.Id property (which should simply query the FoodId foreign key in the Bars table) produces SQL with a join!

Does anyone know why this is so? Is this standard NHibernate behaviour? Or something to do with the Linq provider? Or maybe even FluentNHibernate (which I'm using for mapping)?

Thanks

David

+1  A: 

This behavior is caused by NHibernate.Linq (I believe it relates to the way that the expression is converted into an ICriteria representation of the query). As far as I know, there's no way around this using Nhibernate.Linq directly, but you could achieve the results that you're looking for by using HQL or ICriteria directly.

DanP
The crown of Linq-to-NHibernate is very slightly tarnished.
David
This only applies to the **old** Linq provider, which is based on the Criteria API. The new one (3.x) uses HQL and is more efficient in these cases.
Diego Mijelshon
@Diego - thanks for the info, looking forward to the release ver of NH 3.0 :)
DanP
You can already start using Alpha1 (MS would call that a Beta2 or RC)
Diego Mijelshon
@Diego - unfortunately, I still have to call it 'not ready for production' ;)
DanP
In that case, NHibernate 2.1.2 isn't ready for production either. It's the same codebase.
Diego Mijelshon