Esempio n. 1
0
        protected void CreateDbContext()
        {
            DbContext = new AndaroDbContext();

            //Do not enable proxies
            DbContext.Configuration.ProxyCreationEnabled = false;
            //Load navigation properties explicitly
            DbContext.Configuration.LazyLoadingEnabled = false;
        }
Esempio n. 2
0
        private static void CheckForEntititesWithoutStateInterface(AndaroDbContext context)
        {
            var entititiesWithoutState = from e in context.ChangeTracker.Entries()
                                         where !(e.Entity is IObjectWithState)
                                         select e;

            if (entititiesWithoutState.Any())
            {
                throw new NotSupportedException("All entities must implement IObjectWithState");
            }
        }
Esempio n. 3
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);
             }
         }
     }
 }