public void BeforeEachTest() { sessionFactory = new DbContextSessionFactory(); uow = new DbUnitOfWork(sessionFactory); persister = new DbSagaPersister(sessionFactory); saga = GetTestSaga(); }
public DbApiTester() { IdGenerator = HiLoIdGenerator.DbHiloGIdGenerator(1, 1, 1); UnitOfWork = new DbUnitOfWork(Clock, IdGenerator); RoleRepository = new DbRoleRepository(UnitOfWork); AuthUserRepository = new DbAuthUserRepository(RoleRepository, UnitOfWork); UserRepository = new DbUserRepository(UnitOfWork); GameRepository = new DbGameRepository(UnitOfWork); }
public UserModel GetById(Guid id, bool includeInActive = false, bool includeNonPublic = false) { using (var uow = new DbUnitOfWork(_context)) { var repositories = new IRepository[] { _repository }; uow.Enlist(repositories); uow.InitTransaction(); return(Filter(Populate(_repository.GetById(id), includeInActive, includeNonPublic), includeInActive, includeNonPublic)); } }
public IEnumerable <UserModel> GetAll(bool includeInActive = false, bool includeNonPublic = false) { using (var uow = new DbUnitOfWork(_context)) { var repositories = new IRepository[] { _repository }; uow.Enlist(repositories); uow.InitTransaction(); return(Filter(_repository.GetAll().Select(o => Populate(o, includeInActive, includeNonPublic)), includeInActive, includeNonPublic)); } }
public async Task Save <TModel, TModelKeyType, TEntity, TEntityKeyType>(TModel model, CancellationToken cancellationToken, EntityState entityState, bool updateModelAfterCommit = false) where TModel : class, IKey <TModelKeyType> where TModelKeyType : IEquatable <TModelKeyType> where TEntity : class, IKey <TEntityKeyType> where TEntityKeyType : IEquatable <TEntityKeyType> { using (IUnitOfWorkScope <TUnitOfWork> scope = UnitOfWorkScopeFactory.Create(UowFactory)) { DbUnitOfWork dbContext = scope.UnitOfWork as DbUnitOfWork; if (dbContext == null) { throw new InvalidOperationException("Unsupported Unit of Work."); } dbContext.Entry(model).State = entityState; await scope.CommitAsync(cancellationToken); } }
public async Task Save <TModel, TModelKeyType, TEntity, TEntityKeyType>(TModel model, CancellationToken cancellationToken, EntityState entityState, bool updateModelAfterCommit = false) where TModel : class, IKey <TModelKeyType> where TModelKeyType : IEquatable <TModelKeyType> where TEntity : class, IKey <TEntityKeyType> where TEntityKeyType : IEquatable <TEntityKeyType> { using (IUnitOfWorkScope <TUnitOfWork> scope = UnitOfWorkScopeFactory.Create(UowFactory)) { DbUnitOfWork dbContext = scope.UnitOfWork as DbUnitOfWork; if (dbContext == null) { throw new InvalidOperationException("Unsupported Unit of Work."); } var entityEntry = dbContext.ChangeTracker.Entries <TEntity>() .Where(e => !e.Entity.Id.Equals(default(TEntityKeyType))) .Where(e => typeof(TEntityKeyType) == typeof(TModelKeyType) ? e.Entity.Id.Equals(model.Id) : e.Entity.Id.ToString() == model.Id.ToString()) .SingleOrDefault(); if (entityEntry == null) { TEntity entity = Mapper.Map <TModel, TEntity>(model); entityEntry = dbContext.Entry(entity); } entityEntry.State = entityState; if (updateModelAfterCommit) { switch (entityState) { case EntityState.Added: case EntityState.Modified: dbContext.OnCommit += (db, e) => Mapper.Map(entityEntry.Entity, model); // Refresh model in case of DB-assigned values (Identity/timestamp/etc.). break; } } await scope.CommitAsync(cancellationToken); } }
public DebtRepository(DbUnitOfWork unitOfWork) : base(unitOfWork) { }
public QuoteRepository(DbUnitOfWork <DevAVDb> unitOfWork) : base(unitOfWork, x => x.Set <Quote>(), x => x.Id) { }
public ConfigurationRepository(DbUnitOfWork unitOfWork) : base(unitOfWork) { }
public OrderRepository(DbUnitOfWork <DevAVDb> unitOfWork) : base(unitOfWork, x => x.Set <Order>(), x => x.Id) { }
public void SetUp() { _unitOfWork = new DbUnitOfWork(_connection); }
public DebtInstallmentRepository(DbUnitOfWork unitOfWork) : base(unitOfWork) { }
public RepositoryFactory(DbUnitOfWork DbUnitOfWork) { _dbUnitOfWork = DbUnitOfWork; }