public void Initialize(UserContext userContext) { Logger.Log(Resources.FaustMigrationsHistoryAccessor_Initialize, TraceEventType.Verbose); using (var db = new FaustDB(userContext)) { try { db.Database.ExecuteSqlCommand(@" if (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'FaustMigrationsHistory')) begin create table dbo.FaustMigrationsHistory ( FaustMigrationHistoryId int identity(1,1), ReleaseNumber int NOT NULL, ScriptName varchar(max) NOT NULL, LastRun datetime NOT NULL DEFAULT(getdate()), Committed bit default(null), Successful bit default(null), Log text, constraint PK_FaustMigrationsHistory_FaustMigrationHistoryId primary key (FaustMigrationHistoryId) ) end"); } catch (Exception ex) { Logger.Log(string.Format(Resources.FaustMigrationsHistoryAccessor_InitializeError, ex.Message, ex.StackTrace), TraceEventType.Error); throw; } } }
public FaustMigrationHistory Update(FaustMigrationHistory entity, UserContext userContext) { Logger.Log(string.Format(Resources.Accessors_Updating, typeof(FaustMigrationHistory).Name, entity.FaustMigrationHistoryId), TraceEventType.Verbose); using (var db = new FaustDB(userContext)) { db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); } Logger.Log(string.Format(Resources.Accessors_Updated, typeof(FaustMigrationHistory).Name, entity.FaustMigrationHistoryId), TraceEventType.Verbose); return(entity); }
public FaustMigrationHistory[] FindMany(FaustMigrationHistory searchCriteria, UserContext userContext) { Logger.Log(string.Format(Resources.Accessors_FindMany, typeof(FaustMigrationHistory).ToString()), TraceEventType.Verbose); var predicate = SetupFindMany(searchCriteria, userContext); predicate = SearchCriteriaExpression(searchCriteria, predicate); FaustMigrationHistory[] result; using (var db = new FaustDB(userContext)) { result = db.Set <FaustMigrationHistory>().AsExpandable().Where(predicate).ToArray(); } Logger.Log(string.Format(Resources.Accessors_FoundMany, result.Length, typeof(FaustMigrationHistory).ToString()), TraceEventType.Verbose); return(result); }
public FaustMigrationHistory Delete(FaustMigrationHistory entity, UserContext userContext) { if (entity == null) { throw new ArgumentException(Resources.Error_DeleteEntityParameterNull, "entity"); } using (var db = new FaustDB(userContext)) { db.Entry(entity).State = EntityState.Deleted; db.SaveChanges(); } Logger.Log(string.Format(Resources.Accessors_Deleted, typeof(FaustMigrationHistory).Name), TraceEventType.Verbose); return(entity); }
public FaustMigrationHistory[] DeleteDebugEntries(UserContext userContext) { Logger.Log("FaustMigrationsHistoryAccessor - Deleting all debug Migration Histories", TraceEventType.Verbose); FaustMigrationHistory[] deletedHistories = new FaustMigrationHistory[0]; using (var db = new FaustDB(userContext)) { IEnumerable <FaustMigrationHistory> histories = db.Set <FaustMigrationHistory>().Where(fmh => fmh.ReleaseNumber < 0); deletedHistories = histories.ToArray(); histories.ForEach(h => db.Entry(h).State = EntityState.Deleted); db.SaveChanges(); } Logger.Log(string.Format("FaustMigrationsHistoryAccessor - Deleted {0} Migration Histories", deletedHistories.Length), TraceEventType.Verbose); return(deletedHistories); }
public virtual FaustMigrationHistory[] DeleteMany(FaustMigrationHistory searchCriteria, UserContext userContext) { if (searchCriteria == null) { throw new ArgumentException(Resources.Error_SearchParameterNull, "searchCriteria"); } FaustMigrationHistory[] foundArray = FindMany(searchCriteria, userContext); using (var db = new FaustDB(userContext)) { foreach (FaustMigrationHistory entity in foundArray) { db.Entry(entity).State = EntityState.Deleted; } db.SaveChanges(); } Logger.Log(string.Format(Resources.Accessors_DeletedMany, foundArray.Length, typeof(FaustMigrationHistory).Name), TraceEventType.Verbose); return(foundArray); }