public async Task Should_insert_specified_properties_only() { var testEntity = new TestEntity { Id = new Guid("40B5CA93-5C02-48AD-B8A1-12BC13313866"), Name = "Name", Count = 42 }; var testEntities = new[] { testEntity }; var idProperty = typeof(TestEntity).GetProperty(nameof(TestEntity.Id)); var countProperty = typeof(TestEntity).GetProperty(nameof(TestEntity.Count)); var propertyWithBackingField = typeof(TestEntity).GetProperty(nameof(TestEntity.PropertyWithBackingField)); var privateField = typeof(TestEntity).GetField("_privateField", BindingFlags.Instance | BindingFlags.NonPublic); await ActDbContext.BulkInsertAsync(testEntities, new SqlBulkInsertOptions { EntityMembersProvider = new EntityMembersProvider(new MemberInfo[] { idProperty, countProperty, propertyWithBackingField, privateField }) }); var loadedEntities = await AssertDbContext.TestEntities.ToListAsync(); loadedEntities.Should().HaveCount(1); var loadedEntity = loadedEntities[0]; loadedEntity.Should().BeEquivalentTo(new TestEntity { Id = new Guid("40B5CA93-5C02-48AD-B8A1-12BC13313866"), Count = 42 }); }
public async Task Should_insert_entities() { var testEntity = new TestEntity { Id = new Guid("40B5CA93-5C02-48AD-B8A1-12BC13313866"), Name = "Name", Count = 42 }; var testEntities = new[] { testEntity }; await ActDbContext.BulkInsertAsync(testEntities); var loadedEntities = await AssertDbContext.TestEntities.ToListAsync(); loadedEntities.Should().HaveCount(1); var loadedEntity = loadedEntities[0]; loadedEntity.Should().BeEquivalentTo(new TestEntity { Id = new Guid("40B5CA93-5C02-48AD-B8A1-12BC13313866"), Name = "Name", Count = 42 }); }