NHibernate连接和限制条件

NHibernate连接和限制条件,nhibernate,join,criteria,restriction,Nhibernate,Join,Criteria,Restriction,我正试图编写一个NHibernate标准,同时有效地连接和限制。我的数据库看起来像这样 案例--->CustomerProducts案例状态 每个案例都与一个客户产品关联(多个案例对应一个产品) 每个客户都有多个客户产品(一个客户有多个客户产品) 每个案例还有一个案例状态(一个案例状态对应多个案例) 这已通过XML文件进行映射,案例和客户之间的多对多解析(通过客户产品)已通过CustomerProduct映射中的集合进行解析,这意味着CustomerProduct实体具有集合: 顾客 案例 然后

我正试图编写一个NHibernate标准,同时有效地连接和限制。我的数据库看起来像这样

案例--->CustomerProducts案例状态

每个案例都与一个客户产品关联(多个案例对应一个产品)

每个客户都有多个客户产品(一个客户有多个客户产品)

每个案例还有一个案例状态(一个案例状态对应多个案例)

这已通过XML文件进行映射,案例和客户之间的多对多解析(通过客户产品)已通过CustomerProduct映射中的集合进行解析,这意味着CustomerProduct实体具有集合:

顾客

案例

然后,我创建一个键入“Cases”的标准。我需要申请的标准是

  • [varioud status codes]中的状态。这是通过……实现的

    标准.添加(限制.In(“CaseStatus.CaseStatusId”,Status))

  • 现在我只需要为特定的客户Id选择案例。我已经尝试过

    添加(“CustomerProduct.Customer.CustomerId”,CustomerId)

  • 这不起作用,NHibernate告诉我它无法解析到CustomerProduct.Customer.CustomerId的映射

    案例具有CustomerProduct对象的属性

    CustomerProduct具有Customer对象的属性

    Customer具有CustomerId的属性

    你知道为什么它不起作用吗


    谢谢。

    我认为您需要为CustomerProduct创建别名。Customer:

    criteria.CreateAlias("CustomerProduct", "customerProduct");
    criteria.CreateAlias("customerProduct.Customer", "customer");
    criteria.Add(Restrictions.Eq("customer.CustomerId", customerId));
    

    我很惊讶这项限制在没有别名的情况下有效。下面是一个关于使用Criteria API执行联接查询的示例。

    我认为您需要为CustomerProduct创建别名。Customer:

    criteria.CreateAlias("CustomerProduct", "customerProduct");
    criteria.CreateAlias("customerProduct.Customer", "customer");
    criteria.Add(Restrictions.Eq("customer.CustomerId", customerId));
    

    我很惊讶这项限制在没有别名的情况下有效。下面是一个关于使用Criteria API执行连接查询的示例。

    非常有效!非常感谢。非常好用!非常感谢。