public void Run() { ConsoleWriteLines("Sample showing value conversions for a simple immutable class..."); using (var context = new SampleDbContext()) { CleanDatabase(context); ConsoleWriteLines("Save a new entity..."); var entity = new MyEntityType { MyProperty = new ImmutableClass(7) }; context.Add(entity); context.SaveChanges(); ConsoleWriteLines("Change the property value and save again..."); // This will be detected and EF will update the database on SaveChanges entity.MyProperty = new ImmutableClass(77); context.SaveChanges(); } using (var context = new SampleDbContext()) { ConsoleWriteLines("Read the entity back..."); var entity = context.Set <MyEntityType>().Single(); Debug.Assert(entity.MyProperty.Value == 77); } ConsoleWriteLines("Sample finished."); }
public MyEntity(MyEntityType type) { Type = type; }