使用QueryOver时,Nhibernate无法解析属性exception,适用于QueryAll
我有以下问题
基本上我有以下两个片段:
var contactAssociation = session.QueryOver(() => contactAssociationAlias) .Where(() => contactAssociationAlias.Contact.ID == careGiverId && contactAssociationAlias.Client.ID == clientKey) .Where(() => contactAssociationAlias.AclRole.RoleName == "Care Giver") .SingleOrDefault();
和
var contactAssociation = session.Query() .Where(cr => cr.Contact.ID == careGiverId && cr.Client.ID == clientKey) .Where(cr => cr.AclRole.RoleName == "Care Giver") .SingleOrDefault();
第二个工作第一个输出此错误:
Message=could not resolve property: AclRole.RoleCode of: SL.STAdmin.DAL.ContactAssociation
有人知道为什么吗? 先感谢您
您需要在第一个查询中指定Join。 第二个查询中的LINQ提供程序会自动为您执行此操作。
session.QueryOver(() => contactAssociationAlias) .Where(() => contactAssociationAlias.Contact.ID == careGiverId && contactAssociationAlias.Client.ID == clientKey) .JoinQueryOver(() => contactAssociationAlias.AclRole) .Where(a => a.RoleName == "Care Giver") .SingleOrDefault();