Fernando Acosta y Lara Fernando Acosta y Lara - 1 year ago 62
C# Question

How can i save an enum in my context in EF code first version 6

Hi I need to save a single enum in my context, I tryed this:

public class Context : DbContext
public Context() : base("name=Context"){}

MyEnum MyEnum { get; set; }
public DbSet<Object1> Objects{ get; set; }


, when I modify MyEnum it changes its value but after saving changes when I want to use it goes back to the enum of value 0. Heres my modification code:

MyEnum example = MyEnum.Value1;
using (var ctx = new Context())
ctx.CriterioPlanificacion = example;

Answer Source

So I found this old question I made, so i tested it. The migrations after adding a enum to the DbContext are empty, so EF doesnt saves the ints in a DbContext.

Microsoft documentation recommends only using DbSets that only exposes DbSets with collections of TEntities in it

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download