public void Include_on_entity_with_composite_key_Many_To_One_bugs_925_926() { CreateDatabase925(); var loggingFactory = new TestSqlLoggerFactory(); var serviceProvider = new ServiceCollection() .AddEntityFrameworkNpgsql() .AddSingleton <ILoggerFactory>(loggingFactory) .BuildServiceProvider(); using (var ctx = new MyContext925(serviceProvider)) { var query = ctx.Orders.Include(o => o.Customer); var result = query.ToList(); Assert.Equal(5, result.Count); Assert.NotNull(result[0].Customer); Assert.NotNull(result[1].Customer); Assert.NotNull(result[2].Customer); Assert.NotNull(result[3].Customer); Assert.NotNull(result[4].Customer); var expectedSql = @"SELECT ""o"".""Id"", ""o"".""CustomerFirstName"", ""o"".""CustomerLastName"", ""o"".""Name"", ""c"".""FirstName"", ""c"".""LastName"" FROM ""Order"" AS ""o"" LEFT JOIN ""Customer"" AS ""c"" ON (""o"".""CustomerFirstName"" = ""c"".""FirstName"") AND (""o"".""CustomerLastName"" = ""c"".""LastName"")"; Assert.Equal(expectedSql, TestSqlLoggerFactory.Sql); } }
public void Execute1742(CustomerDetails_1742 details) { CreateDatabase925(); var loggingFactory = new TestSqlLoggerFactory(); var serviceProvider = new ServiceCollection() .AddEntityFrameworkNpgsql() .AddSingleton <ILoggerFactory>(loggingFactory) .BuildServiceProvider(); using (var ctx = new MyContext925(serviceProvider)) { var firstName = details.FirstName; ctx.Customers.Where(c => c.FirstName == firstName && c.LastName == details.LastName).ToList(); const string expectedSql = @"@__firstName_0: Foo @__8__locals1_details_LastName_1: Bar SELECT ""c"".""FirstName"", ""c"".""LastName"" FROM ""Customer"" AS ""c"" WHERE (""c"".""FirstName"" = @__firstName_0) AND (""c"".""LastName"" = @__8__locals1_details_LastName_1)"; Assert.Equal(expectedSql, TestSqlLoggerFactory.Sql); } }
public void Include_on_entity_with_composite_key_One_To_Many_bugs_925_926() { CreateDatabase925(); var loggingFactory = new TestSqlLoggerFactory(); var serviceProvider = new ServiceCollection() .AddEntityFrameworkNpgsql() .AddSingleton <ILoggerFactory>(loggingFactory) .BuildServiceProvider(); using (var ctx = new MyContext925(serviceProvider)) { var query = ctx.Customers.Include(c => c.Orders).OrderBy(c => c.FirstName).ThenBy(c => c.LastName); var result = query.ToList(); Assert.Equal(2, result.Count); Assert.Equal(2, result[0].Orders.Count); Assert.Equal(3, result[1].Orders.Count); var expectedSql = @"SELECT ""c"".""FirstName"", ""c"".""LastName"" FROM ""Customer"" AS ""c"" ORDER BY ""c"".""FirstName"", ""c"".""LastName"" SELECT ""o"".""Id"", ""o"".""CustomerFirstName"", ""o"".""CustomerLastName"", ""o"".""Name"" FROM ""Order"" AS ""o"" WHERE EXISTS ( SELECT 1 FROM ""Customer"" AS ""c"" WHERE (""o"".""CustomerFirstName"" = ""c"".""FirstName"") AND (""o"".""CustomerLastName"" = ""c"".""LastName"")) ORDER BY ""o"".""CustomerFirstName"", ""o"".""CustomerLastName"""; Assert.Equal(expectedSql, TestSqlLoggerFactory.Sql); } }
public void Include_on_entity_with_composite_key_Many_To_One_bugs_925_926() { CreateDatabase925(); var loggingFactory = new TestSqlLoggerFactory(); var serviceProvider = new ServiceCollection() .AddEntityFrameworkSqlServer() .AddSingleton <ILoggerFactory>(loggingFactory) .BuildServiceProvider(); using (var ctx = new MyContext925(serviceProvider)) { var query = ctx.Orders.Include(o => o.Customer); var result = query.ToList(); Assert.Equal(5, result.Count); Assert.NotNull(result[0].Customer); Assert.NotNull(result[1].Customer); Assert.NotNull(result[2].Customer); Assert.NotNull(result[3].Customer); Assert.NotNull(result[4].Customer); var expectedSql = @"SELECT [o].[Id], [o].[CustomerFirstName], [o].[CustomerLastName], [o].[Name], [c].[FirstName], [c].[LastName] FROM [Order] AS [o] LEFT JOIN [Customer] AS [c] ON ([o].[CustomerFirstName] = [c].[FirstName]) AND ([o].[CustomerLastName] = [c].[LastName])"; Assert.Equal(expectedSql, TestSqlLoggerFactory.Sql); } }
public void Include_on_entity_with_composite_key_One_To_Many_bugs_925_926() { CreateDatabase925(); var loggingFactory = new TestSqlLoggerFactory(); var serviceProvider = new ServiceCollection() .AddEntityFrameworkSqlServer() .AddSingleton <ILoggerFactory>(loggingFactory) .BuildServiceProvider(); using (var ctx = new MyContext925(serviceProvider)) { var query = ctx.Customers.Include(c => c.Orders).OrderBy(c => c.FirstName).ThenBy(c => c.LastName); var result = query.ToList(); Assert.Equal(2, result.Count); Assert.Equal(2, result[0].Orders.Count); Assert.Equal(3, result[1].Orders.Count); var expectedSql = @"SELECT [c].[FirstName], [c].[LastName] FROM [Customer] AS [c] ORDER BY [c].[FirstName], [c].[LastName] SELECT [o].[Id], [o].[CustomerFirstName], [o].[CustomerLastName], [o].[Name] FROM [Order] AS [o] INNER JOIN ( SELECT DISTINCT [c].[FirstName], [c].[LastName] FROM [Customer] AS [c] ) AS [c0] ON ([o].[CustomerFirstName] = [c0].[FirstName]) AND ([o].[CustomerLastName] = [c0].[LastName]) ORDER BY [c0].[FirstName], [c0].[LastName]"; Assert.Equal(expectedSql, TestSqlLoggerFactory.Sql); } }
public void Execute1742(CustomerDetails_1742 details) { CreateDatabase925(); var loggingFactory = new TestSqlLoggerFactory(); var serviceProvider = new ServiceCollection() .AddEntityFramework() .AddSqlServer() .ServiceCollection() .AddInstance <ILoggerFactory>(loggingFactory) .BuildServiceProvider(); using (var ctx = new MyContext925(serviceProvider)) { var firstName = details.FirstName; ctx.Customers.Where(c => c.FirstName == firstName && c.LastName == details.LastName).ToList(); const string expectedSql = @"@__firstName_0: Foo @__8__locals1_details_LastName_1: Bar SELECT [c].[FirstName], [c].[LastName] FROM [Customer] AS [c] WHERE ([c].[FirstName] = @__firstName_0) AND ([c].[LastName] = @__8__locals1_details_LastName_1)"; Assert.Equal(expectedSql, TestSqlLoggerFactory.Sql); } }
private void CreateDatabase925() { using (var context = new MyContext925(_fixture.ServiceProvider)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var order11 = new Order { Name = "Order11" }; var order12 = new Order { Name = "Order12" }; var order21 = new Order { Name = "Order21" }; var order22 = new Order { Name = "Order22" }; var order23 = new Order { Name = "Order23" }; var customer1 = new Customer { FirstName = "Customer", LastName = "One", Orders = new List <Order> { order11, order12 } }; var customer2 = new Customer { FirstName = "Customer", LastName = "Two", Orders = new List <Order> { order21, order22, order23 } }; context.Customers.Add(customer1, customer2); context.Orders.Add(order11, order12, order21, order22, order23); context.SaveChanges(); } }