I'm trying to update an entity using a stub. This works fine for changing records, unless I try to set the value back to the default value forr the column. Eg: If the default value is 0, I can change to and from any value except zero, but the changes aren't saved if I try to set it back to zero. This is the code I'm using:
var package = new Package() {
PackageID = 4
};
...
public static void EditPackage(Package package) {
using(var context = new ShopEntities()) {
context.Packages.MergeOption = MergeOption.NoTracking;
var existing = new Package() {
PackageID = package.PackageID
};
context.AttachTo("Packages", existing);
context.ApplyPropertyChanges("ShopEntities.Packages", package);
context.AcceptAllChanges(); // doesn't make a difference
System.Diagnostics.Debug.WriteLine((package.DateSent.HasValue ? package.DateSent.Value.ToString("D") : "none") + "\t\t" + package.IsReceived);
context.SaveChanges();
}
}
In the example above, DateSent's default value is null (It's a DateTime?), and I can also set it to any value other than null, and the debug line confirms the correct properties are set, they're just not saved. I think I must be missing something.
Thanks for any help.