开发者

subquery Problem in Linq To Nhibernate

开发者 https://www.devze.com 2023-03-28 13:23 出处:网络
I have two classes by Names : Person and Asset by Relation type : One To Many(one person by many asset)

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号