views:

66

answers:

1

I'm using NHibernate with Lambda Extensions and I can't figure out how to phrase a specific kind of query.

My application lets users tag other users in pictures. So there are Picture objects, and each Picture has one or more Tag objects, and each Tag object has one User object.

I'm implementing a search feature. Given a search string, I want to return all Pictures whose Name contains the string or which have any Tags with a User whose Name contains the string.

I don't know how to assemble this query, or whether I need to do it with subqueries or aliases. What would be the proper way to do this?

A: 

In Lamdba I don't know but you can use alias to search on the collection ?

session.CreateCriteria<Picture>()
    .CreateAlias("Tags", "tags")
    .Add(
    Expression.Or(
        Expression.Eq("Name","term"),
        Expression.Eq("tags.User.Name","term")));
Matthieu