public void Shadow_properties_are_not_included_in_update_unless_value_explicitly_set() { int id; using (var context = new TheShadows()) { var entry = context.Add(new Dark()); Assert.NotEqual(0, id = entry.Property <int>("Id").CurrentValue); Assert.Equal(0, entry.Property <int>("SomeInt").CurrentValue); Assert.Null(entry.Property <string>("SomeString").CurrentValue); entry.Property <int>("SomeInt").CurrentValue = 77; entry.Property <string>("SomeString").CurrentValue = "Morden"; context.SaveChanges(); } AssertValuesSaved(id, 77, "Morden"); using (var context = new TheShadows()) { var entry = context.Entry(new Dark()); entry.Property <int>("Id").CurrentValue = id; entry.State = EntityState.Modified; context.SaveChanges(); } AssertValuesSaved(id, 77, "Morden"); using (var context = new TheShadows()) { var entry = context.Entry(new Dark()); entry.Property <int>("Id").CurrentValue = id; entry.Property <int>("SomeInt").CurrentValue = 78; entry.Property <string>("SomeString").CurrentValue = "Mr"; entry.State = EntityState.Modified; context.SaveChanges(); } AssertValuesSaved(id, 78, "Mr"); using (var context = new TheShadows()) { var entry = context.Entry(new Dark()); entry.Property <int>("Id").CurrentValue = id; entry.State = EntityState.Modified; entry.Property <int>("SomeInt").CurrentValue = 0; entry.Property <string>("SomeString").CurrentValue = null; context.SaveChanges(); } AssertValuesSaved(id, 0, null); }
private static void AssertValuesSaved(int id, int someInt, string someString) { using (var context = new TheShadows()) { var entry = context.Entry(context.Set <Dark>().Single(e => EF.Property <int>(e, "Id") == id)); Assert.Equal(id, entry.Property <int>("Id").CurrentValue); Assert.Equal(someInt, entry.Property <int>("SomeInt").CurrentValue); Assert.Equal(someString, entry.Property <string>("SomeString").CurrentValue); } }
public void Shadow_properties_are_not_included_in_update_unless_value_explicitly_set() { int id; using (var context = new TheShadows()) { var entry = context.Add(new Dark()); Assert.NotEqual(0, id = entry.Property<int>("Id").CurrentValue); Assert.Equal(0, entry.Property<int>("SomeInt").CurrentValue); Assert.Null(entry.Property<string>("SomeString").CurrentValue); entry.Property<int>("SomeInt").CurrentValue = 77; entry.Property<string>("SomeString").CurrentValue = "Morden"; context.SaveChanges(); } AssertValuesSaved(id, 77, "Morden"); using (var context = new TheShadows()) { var entry = context.Entry(new Dark()); entry.Property<int>("Id").CurrentValue = id; entry.State = EntityState.Modified; context.SaveChanges(); } AssertValuesSaved(id, 77, "Morden"); using (var context = new TheShadows()) { var entry = context.Entry(new Dark()); entry.Property<int>("Id").CurrentValue = id; entry.Property<int>("SomeInt").CurrentValue = 78; entry.Property<string>("SomeString").CurrentValue = "Mr"; entry.State = EntityState.Modified; context.SaveChanges(); } AssertValuesSaved(id, 78, "Mr"); using (var context = new TheShadows()) { var entry = context.Entry(new Dark()); entry.Property<int>("Id").CurrentValue = id; entry.State = EntityState.Modified; entry.Property<int>("SomeInt").CurrentValue = 0; entry.Property<string>("SomeString").CurrentValue = null; context.SaveChanges(); } AssertValuesSaved(id, 0, null); }
private static void AssertValuesSaved(int id, int someInt, string someString) { using (var context = new TheShadows()) { var entry = context.Entry(context.Set<Dark>().Single(e => EF.Property<int>(e, "Id") == id)); Assert.Equal(id, entry.Property<int>("Id").CurrentValue); Assert.Equal(someInt, entry.Property<int>("SomeInt").CurrentValue); Assert.Equal(someString, entry.Property<string>("SomeString").CurrentValue); } }