NHibernate Projection List

I have the following code:

criteria.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("_personId")), "_ personId")
.Add(Projections.Property("_firstName"), "_firstName")
.Add(Projections.Property("_lastName"), "_lastName")
.Add(Projections.Property("_address"), "_ address ")                
.SetResultTransformer(Transformers.AliasToBean(typeof(Person)));

I get the following error: NHibernate.QueryException: property does not map to a single column: _address

_address is a Person component in Nhibernate Mapping.

Can I use Projections.Property for a component?

+3
source share
1 answer

I don’t think you can use the _address component, you will have to use the individual column names that make up the _address component.

So something like

.CreateAlias("Person.Address", "Address")    
.Add(Projections.Property("_streetName"), "Address.streetOne")                
0
source

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


All Articles