views:

22

answers:

0

Using NHibernate, I am trying to set the value of a class contained within another class. For example:

public class Object
{
public virtual string CODE { get; set; }
public virtual string INFO { get; set; }
public virtual int ID { get; set; }
public virtual Location location { get; set; }
}

public class Location
{
public virtual string CODE { get; set; }
}

Object.hbm.xml is:
...
property name="CODE" type="string"
....
many-to-one name="location" column="LOCATION_ID" fetch="join"

And my projection code is:
IList-Object- criteria = Session.CreateCriteria(typeof(Object), "object")
.CreateAlias("location", "locationtAlias")
.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("object.CODE"), "CODE")
...
.Add(Projections.Property("locationtAlias.CODE"), "location.CODE")

This results in an error message: Could not find a setter for property location.CODE in class Object.

The getter is working for the Location class becuase if I set the locationtAlias.CODE to a property in my Object class: ex., object.INFO it works with correct data. However, I am not able to set the value in the Location class. I know I can use a DTO, however that is not dynamic. What I am after is the ability to dynamically project returned data from a class which contains other classes with properties.