Hello I tried another approach. FYI I'm using NHibernate 3.1 :
Operation operations = null;
UserViewModel uvm = null
var ret = GetSession().QueryOver<User>().Where(u => u.AccessKeyId ==
accessKeyId)
.Left.JoinQueryOver(x => x.Operations, () => operations)
.SelectList(list =>
list
.SelectGroup(x
=> x.Id).WithAlias(() => uvm.Id)
.SelectSum(x =>
operations.NbSuccessfulAccesses).WithAlias(() =>
uvm.TotalSuccessfulAccesses)
.SelectSum(x =>
operations.NbFailedAccesses).WithAlias(() => uvm. TotalFailedAccesses))
.TransformUsing(Transformers.AliasToBean<UserViewModel>()).List<
UserViewModel >();
That's generate a correct SQL that brings the correct results. Execution of
the query works well and NHibernate doesn't yield any errors.
However SelectGroup is mapped correctly to the instance 'ret' and SelectSum
are not. Am I missing something ? Why the SelectSum are not mapped in the
resulting instance ?
Thanks for your help.
Thomas
De : [email protected] [mailto:[email protected]] De la part
de Thomas JASKULA
Envoyé : mercredi 27 avril 2011 12:43
À : [email protected]
Objet : [nhusers] RE: NHibernate projecting child entities into parent
properties with Linq or QueryOver
Hello,
According to the answer
http://stackoverflow.com/questions/5796036/nhibernate-projecting-child-entit
ies-into-parent-properties-with-linq-or-queryove?tab=active#tab-top using
Criteria I came up with a translation to QueryOver like this :
Operation operations = null;
var q = GetSession().QueryOver<User>().Where(u => u.AccessKeyId ==
accessKeyId)
.Left.JoinQueryOver(x => x.Operations, () => operations)
.Select(Projections.ProjectionList()
.Add(Projections.Sum<User>(x => callWebServicesView. NbSuccessfulAccesses),
"TotalSuccessfulAccesses"))
.Add(Projections.Sum<User>(x => callWebServicesView. NbFailedAccesses),
"TotalSuccessfulAccesses"))
.TransformUsing(Transformers.AliasToBean<UserViewModel>()).List<
UserViewModel >();
which works great.
However it seems that I have to use string to the name of alias
"TotalSuccessfulAccesses" and "TotalSuccessfulAccesses" because if I use
something like that
UserViewModel userView = null;
.Add(Projections.Sum<User>(x => callWebServicesView. NbSuccessfulAccesses),
() => userView.TotalSuccessfulAccesses)
NHibernate yields an error :
Could not find a setter for property 'userView.TotalSuccessfulAccesses' in
class 'Domain.Query.UserViewModel'
which is not true because there is a setter for TotalSuccessfulAccesses'
property.
Any thoughts ?
Thank you in advance.
Thomas
De : Thomas JASKULA [mailto:[email protected]]
Envoyé : mardi 26 avril 2011 23:30
À : [email protected]
Objet : NHibernate projecting child entities into parent properties with
Linq or QueryOver
Hello,
I’m trying to make a projection with QueryOver. I posted my question on SO
because I’m stuck with it. Here’s the link
http://stackoverflow.com/questions/5796036/nhibernate-projecting-child-entit
ies-into-parent-properties-with-linq-or-queryove. Thanks in advance for your
help.
Thomas
--
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.