How can I make EF Core database first use Enums?

后端 未结 7 946
灰色年华
灰色年华 2020-12-06 04:43

I\'m using EF Core with database-first approach using the \"Scaffold-DbContext\"-command to generate my DbContext / Entities.

How can I instruct Scaffold-DbContext t

7条回答
  •  -上瘾入骨i
    2020-12-06 05:12

    Try this solution:

    public enum StateEnum {
          Ok = 1,
          Fail = 2
    }
    
    public partial class Foo
    {
        public int Id { get; set; }
        public int StateId { get; set; }
        public StateEnum State
        {
            get => (StateEnum)StateId;
            set => StateId = (int)value;
        }
    }
    

提交回复
热议问题