subquery Problem in Linq To Nhibernate
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 q开发者_StackOverflow中文版uery 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
Just do
var q= (from Asset a in SessionInstance.Linq<Asset>()
select a.Person).ToList();
精彩评论