Example #1
0
 public static void DeleteModel <TObject>(TObject model /*, bool saveAssociations=true*/) where TObject : class, IEntityObject <TObject>
 {
     using (var context = new ModelsDbContext())
     {
         try
         {
             model.DropAssociations();
             context.Entry(model).State = EntityState.Deleted;
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             throw new Exception("Failed To Save Model " + typeof(TObject), ex);
         }
     }
 }
Example #2
0
        public static void SaveModel <TObject>(TObject model /*, bool saveAssociations=true*/) where TObject : class, IEntityObject <TObject>
        {
            using (var context = new ModelsDbContext())
            {
                try
                {
                    model.DropAssociations();
                    EntityState state = EntityState.Unchanged;
                    state = context.Set <TObject>().Any(model.ObjectGuid()) ? EntityState.Modified : EntityState.Added;
                    context.Entry(model).State = state;

                    /*if (saveAssociations)
                     * {
                     *
                     * }*/
                    context.SaveChanges();
                    context.Entry(model).Reload();
                }
                catch (Exception ex)
                {
                    throw new Exception("Failed To Save Model " + typeof(TObject), ex);
                }
            }
        }