简体   繁体   中英

Entity Framework and enum with flags not mapped to db

I have class with enum:

 [Flags]
    public enum FlyerStatus
    {
        None = 0,
        Deleted = 1 << 0,
        Validated = 1 << 1,
        Active = 1 << 2
    }

There is not configuration in Fluent.API or Data Annotations.

When I add migrations or automigrations are enabled the property is not mapped to db. That column do no exist. No error or smth. What is going on?

public FlyerStatus Status;

With newest versions, if you annotate the property like this, it will get mapped to an int column in Entity Framework / database:

[EnumDataType(typeof(FlyerStatus))]
public FlyerStatus Status { get; set; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM