开发者

ICriteria query - finding objects whith certain properties in their lists

开发者 https://www.devze.com 2023-01-19 02:40 出处:网络
I have a class B which contains a string \'b\'. I also have a class A which contains a list of Bs (ILi开发者_C百科st) called list.

I have a class B which contains a string 'b'. I also have a class A which contains a list of Bs (ILi开发者_C百科st) called list.

I would like to find all distinct objects of A which contain B objects that contain the string 'bla' in the string 'b'.

Is this possible?

Thanks.

Christian


Sure:

session.CreateQuery(@"
        select distinct a
        from A a
        join a.Bs b
        where b.b = 'bla'
        ").List<A>();

If the relationship is bidirectional (i.e. B has a reference to A), it's even easier:

select distinct b.A
from B b
where b.b = 'bla'

I assumed you meant B.b equals 'bla'. If you meant bla is part of B.b, you can use the LIKE operator just like in SQL

0

精彩评论

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