Best method to store Enum in Database

前端 未结 10 1948
挽巷
挽巷 2020-12-12 12:42

What is the best method of storing an Enum in a Database using C# And Visual Studio and MySQL Data Connector.

I am going to be creating a new project with over 100 E

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 13:07

    We store ours as ints or longs and then we can just cast 'em back and forth. Probably not the most robust solution, but that what we do.

    we are using typed DataSets, so, for example:

    enum BlockTreatmentType 
    {
        All = 0
    };
    
    // blockTreatmentType is an int property
    blockRow.blockTreatmentType = (int)BlockTreatmentType.All;
    BlockTreatmentType btt = (BlockTreatmentType)blockRow.blocktreatmenttype;
    

提交回复
热议问题