Hi Yoann,
This is by design, and is the same as the ICriteria API. You need to tell
the query explicitly to join the associations (i.e., tables).
You can do this using aliases like this:
Profile profileAlias = null;
Job jobAlias = null;
var query =
Session.QueryOver<Suggest>()
.JoinAlias(s => s.Profile, () => profileAlias)
.JoinAlias(s => s.Job, () => jobAlias)
.Where(() => profileAlias.Customer == myCustomerReference)
.And(() => jobAlias.Customer != myCustomerReference);
... which is the analogous to the ICriteria:
var query =
Session.CreateCriteria<Suggest>()
.CreateAlias("Profile", "profileAlias")
.CreateAlias("Job", "jobAlias")
.Add(Restrictions.Eq("profileAlias.Customer", myCustomerReference))
.Add(Restrictions.Not(Restrictions.Eq("jobAlias.Customer",
myCustomerReference)));
Note: if you compare your object references in any of the NHibernate query
languages, NHibernate will turn it into a comparison against the Id in the
generated SQL (so you can compare jobAlias.Customer with a Customer object,
you don't need to compare jobAlias.Customer.Id with your object's Id).
Some additional references:
http://nhforge.org/blogs/nhibernate/archive/2009/12/17/queryover-in-nh-3-0.aspx#Associations
http://nhforge.org/blogs/nhibernate/archive/2009/12/17/queryover-in-nh-3-0.aspx#Aliases
Hope that helps.
Cheers,
Richard
--------------------------------------------------
From: <[email protected]>
Sent: Sunday, June 13, 2010 4:05 AM
To: "nhusers" <[email protected]>
Subject: [nhusers] Re: QueryOver Issue
Usually this is due to bad mapping, but any of the new LINQ stuff only
digs 3 levels deep in the object graph that I've seen (though this may
be configurable). I wouldn't consider this to be a bug as much as a
design decision but one of the devs could probably answer that better.
On Jun 12, 9:43 pm, "Yoann. B" <[email protected]> wrote:
Hi,
Why QueryOver.Where only works on one objet level path ?
Here is my query :
var query = Session.QueryOver<Suggest>()
.Where(p => p.Profile.Customer.CustomerId ==
customerId)
.Where(p => p.Job.Customer.CustomerId != customerId);
var total = query.RowCount();
return total;
I've got an exception : "could not resolve property :
Profile.Customer.CustomerId" and "could not resolve property :
Job.Customer.CustomerId"
Using the LINQ Provider it works.
Am i wrong with the QueryOver API ?
Thanks.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.