Nhibernate was unable to resolve property exception when using QueryOver, runs on QueryAll

I have the following problem: Basically, I have 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 displays this error:

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

Does anyone know why this is? Thank you in advance

+6
source share
1 answer

You need to specify Join in the first request. The LINQ provider in the second query does this 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(); 
+14
source

Source: https://habr.com/ru/post/890628/


All Articles