1
votes

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

1 Answers

1
votes

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.