How do you map an enum as an int value with fluent NHibernate?

后端 未结 7 2012
迷失自我
迷失自我 2020-11-27 11:04

Question says it all really, the default is for it to map as a string but I need it to map as an int.

I\'m currently using Persistenc

7条回答
  •  时光说笑
    2020-11-27 11:31

    You should keep the values as int / tinyint in your DB Table. For mapping your enum you need to specify mapping correctly. Please see below mapping and enum sample,

    Mapping Class

    public class TransactionMap : ClassMap Transaction
    {
        public TransactionMap()
        {
            //Other mappings
            .....
            //Mapping for enum
            Map(x => x.Status, "Status").CustomType();
    
            Table("Transaction");
        }
    }
    

    Enum

    public enum TransactionStatus
    {
       Waiting = 1,
       Processed = 2,
       RolledBack = 3,
       Blocked = 4,
       Refunded = 5,
       AlreadyProcessed = 6,
    }

提交回复
热议问题