AliasToBean with nested type - "Could not find a setter for property"

1,496 views
Skip to first unread message

JamesSpibey

unread,
Jun 30, 2009, 6:25:00 AM6/30/09
to nhusers
Hi,

I have a class which is as follows

Class SearchFilter
Public Property SearchFilterID As Integer
Public Property SearchFilterName As String
...
End Class

Public Class SearchFilterCount
Public Property SearchFilterCountID As Integer
Public Property SearchFilter As SearchFilter
Public Property ItemCount As Integer
End Class

I am trying to return a SearchFilterCount object from a ICriteria
query as follows (removed some details for clarity)

qry.CreateAlias("SearchFilter", "sf",
SqlCommand.JoinType.InnerJoin) _
.SetProjection(Projections.ProjectionList() _
.Add(Projections.GroupProperty
("sf.SearchFilterID"), "SearchFilterID") _
.Add(Projections.GroupProperty
("sf.SearchFilterName"), "SearchFilterName") _
.Add(Projections.GroupProperty
("sf.SearchGroup"), "SearchGroup") _
.Add(Projections.GroupProperty
("sf.DisplayOrder"), "DisplayOrder") _
.Add(Projections.CountDistinct
("Contract.ContractID"), "ItemCount")) _
.SetResultTransformer
(Transformers.AliasToBean(GetType(SearchFilterCount)))

The sql is produced correctly but the AliasToBean method cannot map
the SearchFilterCount object. I get the following error

"Could not find a setter for property 'SearchFilterID' in class
'SearchFilterCount'"

I've tried prefixing the projected values with the name of the nested
class, i.e.

.Add(Projections.GroupProperty("sf.SearchFilterID"),
"SearchFilter.SearchFilterID") _

but that didn't work either.

Is there a way to do this?

Thanks

James

JamesSpibey

unread,
Jun 30, 2009, 2:07:30 PM6/30/09
to nhusers
I figured this out. You can just group the whole association, so
instead of

.Add(Projections.GroupProperty("sf.SearchFilterID"), "SearchFilterID")
_
.Add(Projections.GroupProperty("sf.SearchFilterName"),
"SearchFilterName") _
.Add(Projections.GroupProperty("sf.SearchGroup"), "SearchGroup") _
.Add(Projections.GroupProperty("sf.DisplayOrder"), "DisplayOrder") _

You can just use

.Add(Projections.GroupProperty("SearchFilter"), "SearchFilter")
Reply all
Reply to author
Forward
0 new messages