简体   繁体   English

NHibernate QueryOver用于复杂模型

[英]NHibernate QueryOver For Complex Model

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. 我有一个域对象,我正在尝试使用QueryOver来搜索子,子集合的属性,但是我不确定如何使用QueryOver来解决这个问题。

The POCOs look like this: POCO如下所示:

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? 使用NHibernate的QueryOver,我可以加入到我的Request集合中,但是我将如何进入RequestIndividual集合中以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: 更新 :完整的查询如下所示,并且通过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. 有一个完整的QueryOver方法“集合”,而不是x => x. are () => alias. () => 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? 我通常总是喜欢使用它们(并使用JoinAlias而不是JoinQueryOver ),因为它明确表明了您的意思(对于JoinQueryOver您必须考虑... x => x. ,但是x是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM