I have a domain object that I'm trying to use QueryOver on to search a property of a sub, sub collection and I'm not sure how to approach this using QueryOver.
The POCOs look like this:
public class Case {
public virtual string CaseId { get; set; }
public virtual string CaseNumber { get; set; }
public virtual IList<Request> Requests { get; set; }
}
It has a collection of Requests:
public class Request {
public virtual int RequestId { get; set; }
public virtual IList<RequestIndividual> RequestIndividuals { get; set; }
}
Which has a collection of Request Individuals:
public class RequestIndividual {
public virtual int RequestId { get; set; }
public virtual string IndividualType { get; set; }
public virtual string FirstName { get; set; }
public virtual string MiddleName { get; set; }
public virtual string LastName { get; set; }
public virtual string Company { get; set; }
}
Using NHibernate's QueryOver, I'm able to Join to get to my Request collection, but how would I get into the RequestIndividual collection to find one by FirstName?
var query = _session.QueryOver<Case>();
if (!string.IsNullOrEmpty(finder.IndividualFirstName))
{
query.JoinAlias(x => x.Requests, () => reuestsAlias, JoinType.LeftOuterJoin)
// This is where I'm stumped. How to query the request for the individuals and find the first name?
}
UPDATE : The complete query looks like this and works, thanks to, xanatos:
query.JoinAlias(x => x.Requests, () => reuestsAlias, JoinType.LeftOuterJoin)
.JoinAlias(() => reuestsAlias.RequestIndividuals, () => requestIndividiualAlias)
.Where(() => requestIndividiualAlias.FirstName == finder.IndividualFirstName);
From here
query.JoinAlias(x => x.Requests, () => reuestsAlias, JoinType.LeftOuterJoin)
You do this:
RequestIndividual requestIndividualAlias;
query.JoinAlias(() => reuestsAlias.RequestIndividuals, () => requestIndividualAlias);
There is a whole "set" of QueryOver
methods that instead of being x => x.
are () => alias.
. I normally ALWAYS prefer to use them (and to use JoinAlias
instead of JoinQueryOver
) because it's explicit what you are speaking of (with JoinQueryOver
you have to think... x => x.
, but x
what is?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.