FluentNHibernate: returning an enum from a derived property
I'm using the automapping feature of FluentNHibernate and need a property that derives its return value. This property must return an Enum value, 开发者_运维技巧e.g.
public virtual MyEnum MyDerivedProperty
{
get
{
MyEnum retval;
// do some calculations
return retval;
}
}
Currently I get the following exception:
NHibernate.PropertyNotFoundException: Could not find a setter for property 'MyDerivedProperty' ...
If I add a setter then the database table involved requires the column to exist, even if that setter does nothing.
It works fine when the return type is an int.
Any ideas how I achieve this?
It seems that I need to create a method for anything that returns an object type or enum value. For example:
public virtual MyEnum MyDerivedProperty()
{
MyEnum retval;
// do some calculations
return retval;
}
If it returns a simple type (int, string, etc) I can have a read-only property which does not need to exist as a column in a database table.
精彩评论