Exemplo n.º 1
0
        protected SimpleBenchmarkEntity GenerateSimpleBenchmarkEntity(int entityIndex, SimpleBenchmarkEntity entity = null)
        {
            if (entity == null)
            {
                entity = new SimpleBenchmarkEntity();
            }

            entity.FirstName   = $"First Name {entityIndex}";
            entity.LastName    = $"Last Name {entityIndex}";
            entity.DateOfBirth = new SqlDateTime(DateTime.Now).Value;

            return(entity);
        }
Exemplo n.º 2
0
        public void WhenIUpdateAllTheSingleIntKeyEntitiesThatIPreviouslyInsertedUsingEntityFramework()
        {
            var entityCount = _testContext.LocalInsertedEntities.Count;

            for (var entityIndex = 0; entityIndex < _testContext.LocalInsertedEntities.Count; entityIndex++)
            {
                var oldEntity = _testContext.LocalInsertedEntities[entityIndex] as SimpleBenchmarkEntity;
                var newEntity = new SimpleBenchmarkEntity();
                newEntity.Id = oldEntity.Id;

                using (var dbContext = new EfDbContext(_testContext.DatabaseConnection, _compiledModel, false))
                {
                    dbContext.BenchmarkEntities.Attach(newEntity);
                    this.GenerateSimpleBenchmarkEntity(entityCount++, newEntity);
                    dbContext.SaveChanges();
                }
                _testContext.LocalInsertedEntities[entityIndex] = newEntity;
            }
        }