private void UpdateValueOfflineSystemWCF(Category category) { using (var ctx = new Entities.NorthwindEntities()) { ctx.Categories.Attach(category); var entry = ctx.ObjectStateManager.GetObjectStateEntry(category); entry.SetModifiedProperty("Description"); entry.SetModifiedProperty("SomePropertyToSet"); ctx.SaveChanges(); } }
private void UpdateObjectWithApplyCurrentValues(Entities.NorthwindEntities ctx, Category cat) { var category = ctx.Categories.OfType <Category>().First(c => c.CategoryID == cat.CategoryID); ctx.Categories.ApplyCurrentValues(category); var entry = ctx.ObjectStateManager.GetObjectStateEntry(category); var originalValues = entry.GetUpdatableOriginalValues(); var modifiedProperties = entry.GetModifiedProperties(); originalValues.SetValue(originalValues.GetOrdinal("Description"), cat.Description); ctx.SaveChanges(); }
public void TestSaveChanges() { using (var ctx = new Entities.NorthwindEntities()) { ctx.SavingChanges += new EventHandler(ctx_SavingChanges); var region = ctx.Regions.CreateObject(); region.RegionDescription = "Sample Region"; ctx.Regions.AddObject(region); ctx.SaveChanges(); var regionAdded = ctx.Regions.FirstOrDefault(r => r.RegionID.Equals(region.RegionID)); ctx.Regions.DeleteObject(region); var regionState = ctx.ObjectStateManager.GetObjectStateEntry(region).State; // get the state of the entity var upState = ctx.ObjectStateManager.GetObjectStateEntry(region); //upState.ApplyCurrentValues(region); var originalValues = upState.GetUpdatableOriginalValues(); //ctx.ContextOptions. ctx.SaveChanges(); var context = new Entities.NorthwindEntities(); //regionAdded.RegionDescription = "Updated Region"; ctx.Regions.ApplyCurrentValues(regionAdded); var entry = ctx.ObjectStateManager.GetObjectStateEntry(regionAdded); var origValues = entry.GetUpdatableOriginalValues(); //entry.CurrentValues[] //var entry = ctx.ObjectStateManager.GetObjectStateEntry(regionAdded); //var origValues = entry.GetUpdatableOriginalValues(); //var properties = entry.GetModifiedProperties(); //ctx.DetectChanges(); ctx.SaveChanges(); } }