Nhibernate could not resolve property exception when using QueryOver, works on QueryAll

孤者浪人 提交于 2019-11-29 09:46:38

问题


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();

and

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


回答1:


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();


来源:https://stackoverflow.com/questions/6362317/nhibernate-could-not-resolve-property-exception-when-using-queryover-works-on-q

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!