Beispiel #1
0
 //Only use with short lived contexts
 public static void ApplyStateChanges(this DbContext context)
 {
     foreach (var entry in context.ChangeTracker.Entries <IObjectWithState>())
     {
         IObjectWithState stateInfo = entry.Entity;
         entry.State = StateHelpers.ConvertState(stateInfo.State);
     }
 }
Beispiel #2
0
 public static void ApplyChanges <TEntity>(TEntity root) where TEntity : class, IObjectWithState
 {
     using (var context = new AndaroDbContext())
     {
         context.Set <TEntity>().Add(root);
         CheckForEntititesWithoutStateInterface(context);
         foreach (var entry in context.ChangeTracker.Entries <IObjectWithState>())
         {
             IObjectWithState stateInfo = entry.Entity;
             entry.State = StateHelpers.ConvertState(stateInfo.State);
             if (stateInfo.State == State.Unchanged)
             {
                 var databaseValues = entry.GetDatabaseValues();
                 entry.OriginalValues.SetValues(databaseValues);
             }
         }
     }
 }