コード例 #1
0
 public UnitOfWork(IDbFactory dbFactory)
 {
     DbFactory = dbFactory;
     if (DbFactory.Context()?.State == ConnectionState.Closed)
     {
         DbFactory.Context().Open();
     }
     DbTransaction = DbFactory.Context().BeginTransaction();
     DbClient      = new DapperDbClient(DbFactory, DbTransaction);
 }
コード例 #2
0
        public void Dispose()
        {
            foreach (var person in personRepository.GetAll())
            {
                personRepository.Remove(person);
            }

            dbFactory.Context().SaveChanges();

            personRepository.Dispose();
            dbFactory.Dispose();
        }
コード例 #3
0
        public void Dispose()
        {
            foreach (var place in repository.GetAll())
            {
                repository.Remove(place);
            }

            dbFactory.Context().SaveChanges();

            repository.Dispose();
            dbFactory.Dispose();
        }
コード例 #4
0
        public PersonRepositoryTests()
        {
            dbFactory        = new DbFactory(options);
            personRepository = new PersonRepository(dbFactory);

            personRepository.Add(new Person {
                PersonId = 1, FirstName = "Test", LastName = "Tester", Gender = Gender.Unknown, Status = Status.Unknown
            });
            personRepository.Add(new Person {
                PersonId = 2, FirstName = "Foo", LastName = "Tester", Gender = Gender.Female, Status = Status.Living
            });
            personRepository.Add(new Person {
                PersonId = 3, FirstName = "Bar", LastName = "Tester", Gender = Gender.Male, Status = Status.Living
            });

            dbFactory.Context().SaveChanges();
        }
コード例 #5
0
        public GenericRepositoryTests()
        {
            dbFactory  = new DbFactory(options);
            repository = new GenericRepository <Place>(dbFactory);

            repository.Add(new Place {
                PlaceId = 1, Name = "Place 1"
            });
            repository.Add(new Place {
                PlaceId = 2, Name = "Place 2"
            });
            repository.Add(new Place {
                PlaceId = 3, Name = "Place 3"
            });

            dbFactory.Context().SaveChanges();
        }
コード例 #6
0
 public UnitOfWork(IDbFactory dbFactory)
 {
     Db = dbFactory;
     Db.Context().Open();
     DbTransaction = Db.Context().BeginTransaction();
 }