开发者

FluentNHibernate: returning an enum from a derived property

开发者 https://www.devze.com 2022-12-27 05:45 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号