/// <summary> /// Create a new database /// </summary> public void CreateNewDatabase() { _userRepository = null; _documentRepository = null; _commentRepository = null; _logger.LogInfo("UnitOfWork - performing new database creating..."); try { if (_context.Database.Exists()) { _context.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction, "ALTER DATABASE [" + _context.Database.Connection.Database + "] SET SINGLE_USER WITH ROLLBACK IMMEDIATE"); _context.Database.Delete(); _logger.LogInfo(String.Format("UnitOfWork - Old database {0} was dropped.", _context.Database.Connection.Database)); } _context = DocumentsContext.CreateNewDatabase(); _logger.LogInfo(String.Format("UnitOfWork - New database {0} has been created successfully.", _context.Database.Connection.Database)); } catch (Exception e) { _logger.LogError("Create new database error.", e); throw e; } }
/// <summary> /// Constructor /// </summary> public UnitOfWork() { _logger = new SimpleLogger(); _context = DocumentsContext.CreateDatabaseIfNotExists(); _logger.LogInfo("UnitOfWork is being created"); }
/// <summary> /// Public Constructor,initializes privately declared local variables. /// </summary> /// <param name="context"></param> public GenericRepository(DocumentsContext context) { this.Context = context; this.DbSet = context.Set <TEntity>(); }