3

I have two classes

by Names : Person and Asset

by Relation type : One To Many (one person by many asset)

I wrote a query by subquery using linq.Nhibernate 2.2

var sub_q = from Asset a in SessionInstance.Linq<Asset>()                        
            select a.Person.Id;            

var q = from Person p in SessionInstance.Linq<Person>()
        where(sub_q.Contains(p.Id))
        select p;                

List<Person> list = q.ToList<Person>();

I see one Exception in Execution time Message of exception is : Code supposed to be unreachable

Of course following query is true

var sub_q = from Asset a in SessionInstance.Linq<Asset>()                        
            select a.Person.Id;
List<Person> personList = sub_qsub_q.ToList<Person>;
var q = from Person p in SessionInstance.Linq<Person>()
        where (personList.Contains(p.Id))
        select p;                

List<Person> list = q.ToList<Person>();

But not is good for Performance

Ehsan
  • 3,431
  • 8
  • 50
  • 70
  • 3
    Is there a particular reason why you are using NHibernate 2.x and not 3.x? The LINQ provider in 3.x is more powerful than in 2.x – Oliver Hanappi Aug 14 '11 at 12:59

1 Answers1

0

Just do

var q= (from Asset a in SessionInstance.Linq<Asset>()                        
        select a.Person).ToList();
hazzik
  • 13,019
  • 9
  • 47
  • 86