public void Rule_FilterOverProject_does_promote_to_single_Select_if_custom_function_and_doesnt_opt_in() { var expectedSql = @"SELECT [Extent1].[Id] AS [Id], [SqlServer].[MyCustomFunc]([Extent1].[Name]) AS [C1] FROM [dbo].[Blogs] AS [Extent1] WHERE ([SqlServer].[MyCustomFunc]([Extent1].[Name])) > 10"; using (var context = new BlogContext()) { context.Configuration.UseDatabaseNullSemantics = true; context.Configuration.DisableFilterOverProjectionSimplificationForCustomFunctions = false; // false is default, but using explicit valueto make it obvious var query = context.Blogs.Select(b => new { b.Id, Len = CustomFunctions.MyCustomFunc(b.Name) }).Where(b => b.Len > 10); QueryTestHelpers.VerifyDbQuery(query, expectedSql); } }
public void Rule_FilterOverProject_does_not_promote_to_single_Select_if_custom_function_and_does_opt_in() { var expectedSql = @"SELECT [Project1].[Id] AS [Id], [Project1].[C1] AS [C1] FROM ( SELECT [Extent1].[Id] AS [Id], [SqlServer].[MyCustomFunc]([Extent1].[Name]) AS [C1] FROM [dbo].[Blogs] AS [Extent1] ) AS [Project1] WHERE ([Project1].[Id] > 10) AND ([Project1].[C1] > 10)"; using (var context = new BlogContext()) { context.Configuration.UseDatabaseNullSemantics = true; context.Configuration.DisableFilterOverProjectionSimplificationForCustomFunctions = true; var query = context.Blogs.Select(b => new { b.Id, Len = CustomFunctions.MyCustomFunc(b.Name) }).Where(b => b.Id > 10 && b.Len > 10); QueryTestHelpers.VerifyDbQuery(query, expectedSql); } }