Nhibernate 在使用 QueryOver 时无法解决属性异常,适用于 QueryAll [英] Nhibernate could not resolve property exception when using QueryOver, works on QueryAll

查看:18
本文介绍了Nhibernate 在使用 QueryOver 时无法解决属性异常,适用于 QueryAll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题
基本上我有以下 2 个片段:

I have the following problem
Basically I have the 2 snippets below:

var contactAssociation =
    session.QueryOver<ContactAssociation>(() => contactAssociationAlias)
        .Where(() =>
             contactAssociationAlias.Contact.ID == careGiverId &&
             contactAssociationAlias.Client.ID == clientKey)
        .Where(() =>
             contactAssociationAlias.AclRole.RoleName == "Care Giver")
        .SingleOrDefault();

var contactAssociation = session.Query<ContactAssociation>()
    .Where(cr =>
        cr.Contact.ID == careGiverId
        && cr.Client.ID == clientKey)
    .Where(cr =>
        cr.AclRole.RoleName == "Care Giver")
    .SingleOrDefault();

第二个工作第一个输出这个错误:

the second one works the first one outputs this error:

Message=could not resolve property: AclRole.RoleCode of:
SL.STAdmin.DAL.ContactAssociation

有谁知道这是为什么?提前谢谢您

Does anyone know why this is? Thank you in advance

推荐答案

您需要在第一个查询中指定一个 Join.第二个查询中的 LINQ 提供程序会自动为您执行此操作.

You need to specify a Join in the first query. The LINQ provider in the second query does it automatically for you.

session.QueryOver<ContactAssociation>(() => contactAssociationAlias)
   .Where(() =>
       contactAssociationAlias.Contact.ID == careGiverId &&
       contactAssociationAlias.Client.ID == clientKey)
   .JoinQueryOver(() => contactAssociationAlias.AclRole)
       .Where(a => a.RoleName == "Care Giver")
   .SingleOrDefault();

这篇关于Nhibernate 在使用 QueryOver 时无法解决属性异常,适用于 QueryAll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆