[ConditionalFact] // Issue #478 public void Can_use_sequence_with_nullable_key_end_to_end() { var serviceProvider = new ServiceCollection() .AddEntityFrameworkSqlServer() .BuildServiceProvider(); using (var context = new NullableBronieContext(serviceProvider, TestStore.Name, true)) { context.Database.EnsureCreatedResiliently(); } AddEntitiesNullable(serviceProvider, TestStore.Name, true); AddEntitiesNullable(serviceProvider, TestStore.Name, true); AddEntitiesNullable(serviceProvider, TestStore.Name, true); using (var context = new NullableBronieContext(serviceProvider, TestStore.Name, true)) { var pegasuses = context.Unicons.ToList(); for (var i = 0; i < 10; i++) { Assert.Equal(3, pegasuses.Count(p => p.Name == "Twilight Sparkle " + i)); Assert.Equal(3, pegasuses.Count(p => p.Name == "Rarity " + i)); } } }
[Fact] // Issue #478 public void Can_use_identity_with_nullable_key_end_to_end() { var serviceProvider = new ServiceCollection() .AddEntityFramework() .AddSqlServer() .ServiceCollection .BuildServiceProvider(); using (var context = new NullableBronieContext(serviceProvider, "IdentityBronies", useSequence: false)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); } AddEntitiesNullable(serviceProvider, "IdentityBronies", false); AddEntitiesNullable(serviceProvider, "IdentityBronies", false); AddEntitiesNullable(serviceProvider, "IdentityBronies", false); using (var context = new NullableBronieContext(serviceProvider, "IdentityBronies", useSequence: false)) { var pegasuses = context.Unicons.ToList(); for (var i = 0; i < 10; i++) { Assert.Equal(3, pegasuses.Count(p => p.Name == "Twilight Sparkle " + i)); Assert.Equal(3, pegasuses.Count(p => p.Name == "Rarity " + i)); } } }
private static void AddEntitiesNullable(IServiceProvider serviceProvider, string databaseName, bool useSequence) { using (var context = new NullableBronieContext(serviceProvider, databaseName, useSequence)) { for (var i = 0; i < 10; i++) { context.Add( new Unicon { Name = "Twilight Sparkle " + i }); context.Add( new Unicon { Name = "Rarity " + i }); } context.SaveChanges(); } }
private static void AddEntitiesNullable(IServiceProvider serviceProvider, string databaseName, bool useSequence) { using (var context = new NullableBronieContext(serviceProvider, databaseName, useSequence)) { for (var i = 0; i < 10; i++) { context.Add(new Unicon { Name = "Twilight Sparkle " + i }); context.Add(new Unicon { Name = "Rarity " + i }); } context.SaveChanges(); } }
[ConditionalFact] // Issue #478 public void Can_use_identity_with_nullable_key_end_to_end() { var serviceProvider = new ServiceCollection() .AddEntityFrameworkSqlServer() .BuildServiceProvider(); using (var context = new NullableBronieContext(serviceProvider, "IdentityBronies", useSequence: false)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); } AddEntitiesNullable(serviceProvider, "IdentityBronies", false); AddEntitiesNullable(serviceProvider, "IdentityBronies", false); AddEntitiesNullable(serviceProvider, "IdentityBronies", false); using (var context = new NullableBronieContext(serviceProvider, "IdentityBronies", useSequence: false)) { var pegasuses = context.Unicons.ToList(); for (var i = 0; i < 10; i++) { Assert.Equal(3, pegasuses.Count(p => p.Name == "Twilight Sparkle " + i)); Assert.Equal(3, pegasuses.Count(p => p.Name == "Rarity " + i)); } } }