Mapping HasMany with a custom Where clause
I have two entities, a User and a Request. A request has a Supervisor which is just an email address. A User has an email address. I need to have a mapping that basically does a
WHERE Request.Supervisor = User.Email
and populate a List. I can not use a real identifier because a supervisor may not exist in the system yet when the request is made.
I tried something like this:
HasMany(x => x.UserRequests)
.Where(r => r.Supervisor == x.Email)
.Inverse()
.Cascade.None();
But of course it doesn't understand the x.Email part. Is there a way to do this?
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Paul Batum on 06 Apr, 2010 12:29 PM
Just to clarify, you want this mapped as a list that always exists on your domain object, yes? Because if you are just trying to get a list of the user requests (not as a mapped member of one of your domain objects), you should use hql, or the criteria api, or LINQ to NH to do this.
Going with the assumption that you do want this mapped to your domain object, then you are close to a solution - basically you need to write some sql instead of the linq style expression. We allow an expression to be provided because sometimes we can make sense of it but the functionality is pretty limited. You should find an overload that accepts a string - put the sql in there and you should be good to go.
Paul Batum resolved this discussion on 16 May, 2010 06:52 AM.