2

I´m trying that for a couple of days without success...

My classes :

public class ClassA : Entity
{
     public virtual IList<ClassB> MyBClassList{ get; set; }
     public virtual int MyIntA{ get; set; }
}

public class ClassB : Entity
{
     public virtual ClassA MyClassA { get; set; }
     public virtual ClassC MyClassC { get; set; }   

     public virtual double? MyValueB { get; set; }
}

public class ClassC : Entity
{
    public virtual double? MyValueC1 { get; set; }
    public virtual double? MyValueC2 { get; set; }
}

Ok, Now I trying to make my DTO Query :

var list = repositoryA.GetAll() 
          .Select(x => new       
          {
                    Id = x.Id,
                    MyInt = x.MyIntA,
                    BList = x.MyBClassList.DefaultIfEmpty()
                        .Select(y =>         
                         {
                            y.MyValueB,
                            y.MyClassC.MyValueC1,
                            y.MyClassC.MyValueC2 
                         }).ToList()
          });

The Query executes without error, but I got duplicate rows of my BList, and strange results...

Why is that? What Am I doing wrong?

I´m using NHibernate 4.0.0.2 alpha...

Thanks

Paul
  • 12,359
  • 20
  • 64
  • 101
  • I suppose you are using `bag`s not `set`s in your mapping, if this is the case than this behavior is by design. The best online explanation I was able to find is in the Hibernate FAQ this also applies for NHibernate: https://community.jboss.org/wiki/HibernateFAQ-AdvancedProblems#jive_content_id_Hibernate_does_not_return_distinct_results_for_a_query_with_outer_join_fetching_enabled_for_a_collection_even_if_I_use_the_distinct_keyword a solution can be found in this post: http://stackoverflow.com/questions/796889/nhibernate-linq-and-distinctrootentity . Please post your mappings... – Andreas Jul 10 '14 at 11:45
  • Sorry, the jBoss link does not direct you to the proper FAQ entry, it should point to: `Hibernate does not return distinct results for a query with outer join fetching enabled for a collection (even if I use the distinct keyword)?` – Andreas Jul 10 '14 at 11:58

0 Answers0