Hi,

We use NHibernate with Fluent NHibernate and automapping on a postgres 
database. The problem is that since we started using interfaces the order 
by in linq queries dont give back the correct results.

We have the following classes for our entities:

    public interface ITestOrderByModel
    {
        int Key { get; set; }
        ITestOrderBySubModel Sub { get; set; }
    }

    public interface ITestOrderBySubModel
    {
        int Key { get; set; }
        int Dummy { get; set; }
    }

    public class TestOrderByModel : ITestOrderByModel
    {
        public virtual int Key { get; set; }
        public virtual ITestOrderBySubModel Sub { get; set; }
    }

    public class TestOrderBySubModel : ITestOrderBySubModel
    {
        public virtual int Key { get; set; }
        public virtual int Dummy { get; set; }
    }

We use this convention for automapping:

    public class ReferenceConvention : IReferenceConvention
    {
        public void Apply(IManyToOneInstance instance)
        {
            instance.CustomClass(typeof(TestOrderBySubModel));
        }
    }

It results in these mappings:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class xmlns="urn:nhibernate-mapping-2.2" name="Test.TestOrderByModel, 
Test, Version=1.0.4673.26725, Culture=neutral, PublicKeyToken=null" 
table="TestOrderByModel">
    <id name="Key" type="System.Int32, mscorlib, Version=4.0.0.0, 
Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="Key" />
      <generator class="identity" />
    </id>
    <many-to-one cascade="save-update" class="Test.TestOrderBySubModel, 
Test, Version=1.0.4673.26725, Culture=neutral, PublicKeyToken=null" 
name="Sub">
      <column name="Sub" />
    </many-to-one>
  </class>
</hibernate-mapping>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class xmlns="urn:nhibernate-mapping-2.2" name="Test.TestOrderBySubModel, 
Test, Version=1.0.4673.26725, Culture=neutral, PublicKeyToken=null" 
table="TestOrderBySubModel">
    <id name="Key" type="System.Int32, mscorlib, Version=4.0.0.0, 
Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="Key" />
      <generator class="identity" />
    </id>
    <property name="Dummy" type="System.Int32, mscorlib, Version=4.0.0.0, 
Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="Dummy" />
    </property>
  </class>
</hibernate-mapping>

All seems ok but when we use this query:

IQueryable<ITestOrderByModel> queryable = from model in 
Session<ITestOrderByModel>().Query()
                                                                  orderby 
model.Sub.Dummy
                                                                  select 
model;

every model that has it Sub property empy is removed from the result. if we 
remove the orderby every model is returned.

And if we don't uses interfaces in the entities the results are *not*filtered 
and every model is returned.

When we inspect the sql queries we notice that with interfaces a innerjoin 
is used and without interfaces a left outerjoin is used.

Does anyone know how we can fix this problem?

Thanks in advance

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/PhNNUNBNo2oJ.
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