public async Task Can_read_with_find_with_PK_resource_id() { var options = Fixture.CreateOptions(); var customer = new CustomerWithResourceId { id = "42", Name = "Theon" }; await using (var context = new PartitionKeyContextWithPrimaryKeyResourceId(options)) { await context.Database.EnsureCreatedAsync(); context.Add(customer); await context.SaveChangesAsync(); } await using (var context = new PartitionKeyContextWithPrimaryKeyResourceId(options)) { var customerFromStore = context.Set <CustomerWithResourceId>().Find("42"); Assert.Equal("42", customerFromStore.id); Assert.Equal("Theon", customerFromStore.Name); AssertSql( context, @"@__p_0='42' SELECT c FROM root c WHERE ((c[""Discriminator""] = ""CustomerWithResourceId"") AND (c[""id""] = @__p_0)) OFFSET 0 LIMIT 1"); } }
public async Task Can_read_with_find_with_resource_id_async() { var options = Fixture.CreateOptions(); const int pk1 = 1; const int pk2 = 2; var customer = new CustomerWithResourceId { id = "42", Name = "Theon", PartitionKey = pk1 }; await using (var context = new PartitionKeyContextWithResourceId(options)) { await context.Database.EnsureCreatedAsync(); Assert.Null( context.Model.FindEntityType(typeof(CustomerWithResourceId)) .FindProperty(StoreKeyConvention.DefaultIdPropertyName)); context.Add(customer); context.Add( new CustomerWithResourceId { id = "42", Name = "Theon Twin", PartitionKey = pk2 }); await context.SaveChangesAsync(); } await using (var context = new PartitionKeyContextWithResourceId(options)) { var customerFromStore = await context.Set <CustomerWithResourceId>() .FindAsync(pk1, "42"); Assert.Equal("42", customerFromStore.id); Assert.Equal("Theon", customerFromStore.Name); Assert.Equal(pk1, customerFromStore.PartitionKey); AssertSql(context, @"ReadItem(1, 42)"); customerFromStore.Name = "Theon Greyjoy"; await context.SaveChangesAsync(); } await using (var context = new PartitionKeyContextWithResourceId(options)) { var customerFromStore = await context.Set <CustomerWithResourceId>() .WithPartitionKey(partitionKey: pk1.ToString()) .FirstAsync(); Assert.Equal("42", customerFromStore.id); Assert.Equal("Theon Greyjoy", customerFromStore.Name); Assert.Equal(pk1, customerFromStore.PartitionKey); } }
public void Can_read_with_find_with_resource_id() { var options = Fixture.CreateOptions(); const int pk1 = 1; const int pk2 = 2; var customer = new CustomerWithResourceId { id = "42", Name = "Theon", PartitionKey = pk1 }; using (var context = new PartitionKeyContextWithResourceId(options)) { context.Database.EnsureCreated(); context.Add(customer); context.Add( new CustomerWithResourceId { id = "42", Name = "Theon Twin", PartitionKey = pk2 }); context.SaveChanges(); } using (var context = new PartitionKeyContextWithResourceId(options)) { var customerFromStore = context.Set <CustomerWithResourceId>() .Find(pk1, "42"); Assert.Equal("42", customerFromStore.id); Assert.Equal("Theon", customerFromStore.Name); Assert.Equal(pk1, customerFromStore.PartitionKey); AssertSql(context, @"ReadItem(1, 42)"); customerFromStore.Name = "Theon Greyjoy"; context.SaveChanges(); } using (var context = new PartitionKeyContextWithResourceId(options)) { var customerFromStore = context.Set <CustomerWithResourceId>() .WithPartitionKey(partitionKey: pk1.ToString()) .First(); Assert.Equal("42", customerFromStore.id); Assert.Equal("Theon Greyjoy", customerFromStore.Name); Assert.Equal(pk1, customerFromStore.PartitionKey); } }