I have the a class similar to the following (nb! names have been changed to protect the innocent):
public class Person
{
public virtual int Id { get; private set; }
public virtual string Name { get; set; }
public virtual DateTime Birthday { get; set; }
public virtual TimeSpan Age { get { return DateTime.Now - this.Birthday; } }
}
I use Fluent NHibernate to configure my mapping:
public class PersonMap : ClassMap<Person>
{
public PersonMap()
{
Id(x => x.Id);
Map(x => x.Name);
Map(x => x.Birthday);
}
}
The problem is that this throws an exception:
Could not find a setter for property 'Age' in class 'Person'
If Age is not marked virtual I get:
The following types may not be used as proxies: Person: method get_Age should be 'public/protected virtual' or 'protected internal virtual'
Of course it cant find a setter and it shouldn't! How can I make this mapping work?