Mapping to an Enum bit flag in Nhibernate

前端 未结 5 880
北恋
北恋 2020-12-17 14:55

Take the following Enum Flag

[Flags]
enum Permssions
{
   CanComment = 1,
   CanEdit = 2,
   CanDelete = 4,
   CanRemoveUsers = 8,
   All = CanComment | CanE         


        
5条回答
  •  天命终不由人
    2020-12-17 15:25

    I would have a private int field for the NHibernate persistence and a public Getter/Setter property for the flag enum that read and write to the int field. (NHibernate can be configured to work with private fields)

    That way you don't have to resort to voodoo magic or messy constants to get the job done.

提交回复
热议问题