使用QueryOver当NHibernate的无法解析财产例外,适用于QueryAll [英] Nhibernate could not resolve property exception when using QueryOver, works on QueryAll

查看:155
本文介绍了使用QueryOver当NHibernate的无法解析财产例外,适用于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

推荐答案

您需要指定在第一个查询的联接。在第二个查询的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();

这篇关于使用QueryOver当NHibernate的无法解析财产例外,适用于QueryAll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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