tags:

views:

18

answers:

1

Hi,

I have a class B which contains a string 'b'. I also have a class A which contains a list of Bs (IList) 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

A: 

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

Diego Mijelshon
Thanks. SQL and HQL is ok but I was wondering how to do this with ICriteria. I suppose I have to create some alias like list.b ???
csetzkorn
I really don't remember how to do it with Criteria. But why do you need that?
Diego Mijelshon
I am using some existing stuff which has, for example, a method like this: ICriteria GetPagedCriteria<T>(PagedRequest request, bool sort)
csetzkorn
You're unnecessarily limiting yourself. Take a look at http://code.google.com/p/unhaddins/source/browse/#hg/uNhAddIns/uNhAddIns/Pagination
Diego Mijelshon