public void Can_read_with_find_with_partition_key_and_value_generator() { var options = Fixture.CreateOptions(); const int pk1 = 1; const int pk2 = 2; var customer = new Customer { Id = 42, Name = "Theon", PartitionKey = pk1 }; using (var context = new PartitionKeyContextCustomValueGenerator(options)) { context.Database.EnsureCreated(); context.Add(customer); context.Add( new Customer { Id = 42, Name = "Theon Twin", PartitionKey = pk2 }); context.SaveChanges(); } using (var context = new PartitionKeyContextCustomValueGenerator(options)) { var customerFromStore = context.Set <Customer>() .Find(pk1, 42); Assert.Equal(42, customerFromStore.Id); Assert.Equal("Theon", customerFromStore.Name); Assert.Equal(pk1, customerFromStore.PartitionKey); AssertSql(context, @"ReadItem(1, Customer-42)"); customerFromStore.Name = "Theon Greyjoy"; context.SaveChanges(); } using (var context = new PartitionKeyContextCustomValueGenerator(options)) { var customerFromStore = context.Set <Customer>() .WithPartitionKey(partitionKey: pk1.ToString()) .First(); Assert.Equal(42, customerFromStore.Id); Assert.Equal("Theon Greyjoy", customerFromStore.Name); Assert.Equal(pk1, customerFromStore.PartitionKey); } }
public async Task Can_read_with_find_with_partition_key_and_value_generator_async() { var options = Fixture.CreateOptions(); const int pk1 = 1; const int pk2 = 2; var customer = new Customer { Id = 42, Name = "Theon", PartitionKey = pk1 }; await using (var context = new PartitionKeyContextCustomValueGenerator(options)) { await context.Database.EnsureCreatedAsync(); context.Add(customer); context.Add( new Customer { Id = 42, Name = "Theon Twin", PartitionKey = pk2 }); await context.SaveChangesAsync(); } await using (var context = new PartitionKeyContextCustomValueGenerator(options)) { var customerFromStore = await context.Set <Customer>() .FindAsync(pk1, 42); Assert.Equal(42, customerFromStore.Id); Assert.Equal("Theon", customerFromStore.Name); Assert.Equal(pk1, customerFromStore.PartitionKey); customerFromStore.Name = "Theon Greyjoy"; await context.SaveChangesAsync(); } await using (var context = new PartitionKeyContextCustomValueGenerator(options)) { var customerFromStore = await context.Set <Customer>() .WithPartitionKey(partitionKey: pk1.ToString()) .FirstAsync(); Assert.Equal(42, customerFromStore.Id); Assert.Equal("Theon Greyjoy", customerFromStore.Name); Assert.Equal(pk1, customerFromStore.PartitionKey); } }