diff --git a/test/EFCore.Relational.Specification.Tests/Query/NorthwindQueryRelationalFixture.cs b/test/EFCore.Relational.Specification.Tests/Query/NorthwindQueryRelationalFixture.cs index 49d039b7a6a..dd8849cfaa9 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/NorthwindQueryRelationalFixture.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/NorthwindQueryRelationalFixture.cs @@ -22,7 +22,4 @@ public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder build protected override bool ShouldLogCategory(string logCategory) => logCategory == DbLoggerCategory.Query.Name; - - protected override Type ContextType - => typeof(NorthwindRelationalContext); } diff --git a/test/EFCore.Relational.Specification.Tests/TestModels/Northwind/NorthwindRelationalContext.cs b/test/EFCore.Relational.Specification.Tests/TestModels/Northwind/NorthwindRelationalContext.cs index ddc1d6d2dde..7362449f596 100644 --- a/test/EFCore.Relational.Specification.Tests/TestModels/Northwind/NorthwindRelationalContext.cs +++ b/test/EFCore.Relational.Specification.Tests/TestModels/Northwind/NorthwindRelationalContext.cs @@ -3,9 +3,9 @@ namespace Microsoft.EntityFrameworkCore.TestModels.Northwind; -public class NorthwindRelationalContext : NorthwindContext +public abstract class NorthwindRelationalContext : NorthwindContext { - public NorthwindRelationalContext(DbContextOptions options) + protected NorthwindRelationalContext(DbContextOptions options) : base(options) { } diff --git a/test/EFCore.Specification.Tests/TestModels/Northwind/Customer.cs b/test/EFCore.Specification.Tests/TestModels/Northwind/Customer.cs index a62fdfc96d4..2199a8773d1 100644 --- a/test/EFCore.Specification.Tests/TestModels/Northwind/Customer.cs +++ b/test/EFCore.Specification.Tests/TestModels/Northwind/Customer.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Text.Json.Serialization; @@ -20,16 +21,39 @@ public Customer(DbContext context, ILazyLoader lazyLoader, string customerID) CustomerID = customerID; } + [MaxLength(5)] + [Required] public string CustomerID { get; set; } + + [MaxLength(40)] + [Required] public string CompanyName { get; set; } + + [MaxLength(30)] public string ContactName { get; set; } + + [MaxLength(30)] public string ContactTitle { get; set; } + + [MaxLength(60)] public string Address { get; set; } + + [MaxLength(15)] public string City { get; set; } + + [MaxLength(15)] public string Region { get; set; } + + [MaxLength(10)] public string PostalCode { get; set; } + + [MaxLength(15)] public string Country { get; set; } + + [MaxLength(24)] public string Phone { get; set; } + + [MaxLength(24)] public string Fax { get; set; } public virtual List Orders { get; set; } diff --git a/test/EFCore.Specification.Tests/TestModels/Northwind/Employee.cs b/test/EFCore.Specification.Tests/TestModels/Northwind/Employee.cs index 21893f3df9b..e72489855c0 100644 --- a/test/EFCore.Specification.Tests/TestModels/Northwind/Employee.cs +++ b/test/EFCore.Specification.Tests/TestModels/Northwind/Employee.cs @@ -1,6 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + namespace Microsoft.EntityFrameworkCore.TestModels.Northwind; public class Employee @@ -13,22 +16,49 @@ public uint EmployeeID set => _employeeId = value; } + [MaxLength(20)] + [Required] public string LastName { get; set; } + + [MaxLength(10)] + [Required] public string FirstName { get; set; } + + [MaxLength(30)] public string Title { get; set; } + + [MaxLength(25)] public string TitleOfCourtesy { get; set; } + public DateTime? BirthDate { get; set; } public DateTime? HireDate { get; set; } + + [MaxLength(60)] public string Address { get; set; } + + [MaxLength(15)] public string City { get; set; } + + [MaxLength(15)] public string Region { get; set; } + + [MaxLength(10)] public string PostalCode { get; set; } + + [MaxLength(15)] public string Country { get; set; } + + [MaxLength(24)] public string HomePhone { get; set; } + + [MaxLength(4)] public string Extension { get; set; } + public byte[] Photo { get; set; } public string Notes { get; set; } public uint? ReportsTo { get; set; } + + [MaxLength(255)] public string PhotoPath { get; set; } public Employee Manager { get; set; } diff --git a/test/EFCore.Specification.Tests/TestModels/Northwind/NorthwindContext.cs b/test/EFCore.Specification.Tests/TestModels/Northwind/NorthwindContext.cs index 8fb357ea4c3..8a57b800980 100644 --- a/test/EFCore.Specification.Tests/TestModels/Northwind/NorthwindContext.cs +++ b/test/EFCore.Specification.Tests/TestModels/Northwind/NorthwindContext.cs @@ -40,6 +40,15 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) e.HasOne(e1 => e1.Manager).WithMany().HasForeignKey(e1 => e1.ReportsTo); }); + modelBuilder.Entity( + e => + { + e.HasIndex(e => e.City); + e.HasIndex(e => e.CompanyName); + e.HasIndex(e => e.PostalCode); + e.HasIndex(e => e.Region); + }); + modelBuilder.Entity( e => { @@ -47,6 +56,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) e.Ignore(p => p.QuantityPerUnit); e.Ignore(p => p.ReorderLevel); e.Ignore(p => p.UnitsOnOrder); + + e.HasIndex(e => e.ProductName); }); modelBuilder.Entity( @@ -62,6 +73,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) e.Ignore(o => o.ShipRegion); e.Ignore(o => o.ShipVia); e.Ignore(o => o.ShippedDate); + + e.HasIndex(e => e.OrderDate); }); modelBuilder.Entity( diff --git a/test/EFCore.Specification.Tests/TestModels/Northwind/Order.cs b/test/EFCore.Specification.Tests/TestModels/Northwind/Order.cs index 6ca9bd56021..2751bd525e8 100644 --- a/test/EFCore.Specification.Tests/TestModels/Northwind/Order.cs +++ b/test/EFCore.Specification.Tests/TestModels/Northwind/Order.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.ComponentModel.DataAnnotations; + namespace Microsoft.EntityFrameworkCore.TestModels.Northwind; public class Order @@ -13,6 +15,7 @@ public int OrderID set => _orderId = value; } + [MaxLength(5)] public string CustomerID { get; set; } public uint? EmployeeID { get; set; } public DateTime? OrderDate { get; set; } @@ -20,11 +23,23 @@ public int OrderID public DateTime? ShippedDate { get; set; } public int? ShipVia { get; set; } public decimal? Freight { get; set; } + + [MaxLength(40)] public string ShipName { get; set; } + + [MaxLength(60)] public string ShipAddress { get; set; } + + [MaxLength(15)] public string ShipCity { get; set; } + + [MaxLength(15)] public string ShipRegion { get; set; } + + [MaxLength(10)] public string ShipPostalCode { get; set; } + + [MaxLength(15)] public string ShipCountry { get; set; } public Customer Customer { get; set; } = new(); // Initialized to test #23851 diff --git a/test/EFCore.Specification.Tests/TestModels/Northwind/Product.cs b/test/EFCore.Specification.Tests/TestModels/Northwind/Product.cs index d1576e5884d..2e8b2db8c77 100644 --- a/test/EFCore.Specification.Tests/TestModels/Northwind/Product.cs +++ b/test/EFCore.Specification.Tests/TestModels/Northwind/Product.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.ComponentModel.DataAnnotations; + namespace Microsoft.EntityFrameworkCore.TestModels.Northwind; public class Product @@ -18,9 +20,13 @@ public int ProductID set => _productId = value; } + [MaxLength(40)] + [Required] public string ProductName { get; set; } public int? SupplierID { get; set; } public int? CategoryID { get; set; } + + [MaxLength(20)] public string QuantityPerUnit { get; set; } public decimal? UnitPrice { get; set; } public ushort UnitsInStock { get; set; } diff --git a/test/EFCore.SqlServer.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqlServerFixture.cs b/test/EFCore.SqlServer.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqlServerFixture.cs index b7da86b28ec..efd9f243a76 100644 --- a/test/EFCore.SqlServer.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqlServerFixture.cs +++ b/test/EFCore.SqlServer.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqlServerFixture.cs @@ -15,37 +15,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con { base.OnModelCreating(modelBuilder, context); - modelBuilder.Entity() - .Property(c => c.CustomerID) - .HasColumnType("nchar(5)"); - - modelBuilder.Entity( - b => - { - b.Property(c => c.EmployeeID).HasColumnType("int"); - b.Property(c => c.ReportsTo).HasColumnType("int"); - }); - - modelBuilder.Entity( - b => - { - b.Property(o => o.EmployeeID).HasColumnType("int"); - b.Property(o => o.OrderDate).HasColumnType("datetime"); - }); - - modelBuilder.Entity() - .Property(od => od.UnitPrice) - .HasColumnType("money"); - - modelBuilder.Entity( - b => - { - b.Property(p => p.UnitPrice).HasColumnType("money"); - b.Property(p => p.UnitsInStock).HasColumnType("smallint"); - }); - modelBuilder.Entity() .Property(p => p.UnitPrice) .HasColumnType("money"); } + + protected override Type ContextType + => typeof(NorthwindSqlServerContext); } diff --git a/test/EFCore.SqlServer.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqlServerTest.cs index 7f1107a15a9..babc75cf9d6 100644 --- a/test/EFCore.SqlServer.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqlServerTest.cs @@ -605,7 +605,7 @@ public override async Task Update_Where_set_parameter(bool async) await base.Update_Where_set_parameter(async); AssertExecuteUpdateSql( - @"@__value_0='Abc' (Size = 4000) + @"@__value_0='Abc' (Size = 30) UPDATE [c] SET [c].[ContactName] = @__value_0 @@ -618,7 +618,7 @@ public override async Task Update_Where_set_parameter_from_closure_array(bool as await base.Update_Where_set_parameter_from_closure_array(async); AssertExecuteUpdateSql( - @"@__p_0='Abc' (Size = 4000) + @"@__p_0='Abc' (Size = 30) UPDATE [c] SET [c].[ContactName] = @__p_0 @@ -642,7 +642,7 @@ public override async Task Update_Where_set_parameter_from_multilevel_property_a await base.Update_Where_set_parameter_from_multilevel_property_access(async); AssertExecuteUpdateSql( - @"@__container_Containee_Property_0='Abc' (Size = 4000) + @"@__container_Containee_Property_0='Abc' (Size = 30) UPDATE [c] SET [c].[ContactName] = @__container_Containee_Property_0 @@ -922,7 +922,7 @@ public override async Task Update_Where_set_property_plus_parameter(bool async) await base.Update_Where_set_property_plus_parameter(async); AssertExecuteUpdateSql( - @"@__value_0='Abc' (Size = 4000) + @"@__value_0='Abc' (Size = 30) UPDATE [c] SET [c].[ContactName] = COALESCE([c].[ContactName], N'') + @__value_0 @@ -982,7 +982,7 @@ public override async Task Update_Where_multiple_set(bool async) await base.Update_Where_multiple_set(async); AssertExecuteUpdateSql( - @"@__value_0='Abc' (Size = 4000) + @"@__value_0='Abc' (Size = 30) UPDATE [c] SET [c].[City] = N'Seattle', diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/FromSqlQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/FromSqlQuerySqlServerTest.cs index 828d640aa70..045caeeeb3e 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/FromSqlQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/FromSqlQuerySqlServerTest.cs @@ -497,7 +497,7 @@ public override async Task FromSqlRaw_composed_with_nullable_predicate(bool asyn FROM ( SELECT * FROM ""Customers"" ) AS [m] -WHERE [m].[ContactName] = [m].[CompanyName] OR (([m].[ContactName] IS NULL) AND ([m].[CompanyName] IS NULL))"); +WHERE [m].[ContactName] = [m].[CompanyName]"); } public override async Task FromSqlRaw_with_dbParameter(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindChangeTrackingQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindChangeTrackingQuerySqlServerTest.cs index 54d52f57622..6c9c98d3789 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindChangeTrackingQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindChangeTrackingQuerySqlServerTest.cs @@ -282,7 +282,7 @@ private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); protected override NorthwindContext CreateNoTrackingContext() - => new NorthwindRelationalContext( + => new NorthwindSqlServerContext( new DbContextOptionsBuilder(Fixture.CreateOptions()) .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking).Options); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindMiscellaneousQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindMiscellaneousQuerySqlServerTest.cs index 6b12ef2f6fb..6ce322418d2 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindMiscellaneousQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindMiscellaneousQuerySqlServerTest.cs @@ -428,10 +428,7 @@ FROM [Employees] AS [e] WHERE [e].[FirstName] = ( SELECT TOP(1) [e0].[FirstName] FROM [Employees] AS [e0] - ORDER BY [e0].[EmployeeID]) OR (([e].[FirstName] IS NULL) AND (( - SELECT TOP(1) [e0].[FirstName] - FROM [Employees] AS [e0] - ORDER BY [e0].[EmployeeID]) IS NULL))"); + ORDER BY [e0].[EmployeeID])"); } public override async Task Where_query_composition_is_null(bool async) @@ -647,10 +644,7 @@ FROM [Employees] AS [e] WHERE [t].[FirstName] = ( SELECT TOP(1) [e0].[FirstName] FROM [Employees] AS [e0] - ORDER BY [e0].[EmployeeID]) OR (([t].[FirstName] IS NULL) AND (( - SELECT TOP(1) [e0].[FirstName] - FROM [Employees] AS [e0] - ORDER BY [e0].[EmployeeID]) IS NULL))"); + ORDER BY [e0].[EmployeeID])"); } public override async Task Where_query_composition2_FirstOrDefault(bool async) @@ -668,10 +662,7 @@ FROM [Employees] AS [e] WHERE [t].[FirstName] = ( SELECT TOP(1) [e0].[FirstName] FROM [Employees] AS [e0] - ORDER BY [e0].[EmployeeID]) OR (([t].[FirstName] IS NULL) AND (( - SELECT TOP(1) [e0].[FirstName] - FROM [Employees] AS [e0] - ORDER BY [e0].[EmployeeID]) IS NULL))"); + ORDER BY [e0].[EmployeeID])"); } public override async Task Where_query_composition2_FirstOrDefault_with_anonymous(bool async) @@ -689,10 +680,7 @@ FROM [Employees] AS [e] WHERE [t].[FirstName] = ( SELECT TOP(1) [e0].[FirstName] FROM [Employees] AS [e0] - ORDER BY [e0].[EmployeeID]) OR (([t].[FirstName] IS NULL) AND (( - SELECT TOP(1) [e0].[FirstName] - FROM [Employees] AS [e0] - ORDER BY [e0].[EmployeeID]) IS NULL))"); + ORDER BY [e0].[EmployeeID])"); } public override async Task Select_Subquery_Single(bool async) @@ -1536,8 +1524,8 @@ public override async Task Where_select_many_or_with_parameter(bool async) await base.Where_select_many_or_with_parameter(async); AssertSql( - @"@__london_0='London' (Size = 4000) -@__lisboa_1='Lisboa' (Size = 4000) + @"@__london_0='London' (Size = 15) +@__lisboa_1='Lisboa' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] FROM [Customers] AS [c] @@ -5092,7 +5080,7 @@ public override async Task Distinct_followed_by_ordering_on_condition(bool async AssertSql( @"@__p_1='5' -@__searchTerm_0='c' (Size = 4000) +@__searchTerm_0='c' (Size = 15) SELECT TOP(@__p_1) [t].[City] FROM ( @@ -5102,7 +5090,7 @@ WHERE [c].[CustomerID] NOT IN (N'VAFFE', N'DRACD') ) AS [t] ORDER BY CASE WHEN @__searchTerm_0 = N'' THEN 0 - ELSE CAST(CHARINDEX(@__searchTerm_0, [t].[City]) AS int) - 1 + ELSE CHARINDEX(@__searchTerm_0, [t].[City]) - 1 END, [t].[City]"); } @@ -5604,13 +5592,13 @@ public override async Task Where_Property_shadow_closure(bool async) await base.Where_Property_shadow_closure(async); AssertSql( - @"@__value_0='Sales Representative' (Size = 4000) + @"@__value_0='Sales Representative' (Size = 30) SELECT [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] FROM [Employees] AS [e] WHERE [e].[Title] = @__value_0", // - @"@__value_0='Steven' (Size = 4000) + @"@__value_0='Steven' (Size = 10) SELECT [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] FROM [Employees] AS [e] @@ -5718,7 +5706,7 @@ public override async Task Where_Property_when_shadow_unconstrained_generic_meth await base.Where_Property_when_shadow_unconstrained_generic_method(async); AssertSql( - @"@__value_0='Sales Representative' (Size = 4000) + @"@__value_0='Sales Representative' (Size = 30) SELECT [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] FROM [Employees] AS [e] diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindQueryFiltersQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindQueryFiltersQuerySqlServerTest.cs index 4262f618a75..d26724a54d3 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindQueryFiltersQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindQueryFiltersQuerySqlServerTest.cs @@ -31,7 +31,7 @@ public override async Task Count_query(bool async) SELECT COUNT(*) FROM [Customers] AS [c] -WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0)"); +WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0"); } public override async Task Materialized_query(bool async) @@ -44,7 +44,7 @@ public override async Task Materialized_query(bool async) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] -WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0)"); +WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0"); } public override async Task Find(bool async) @@ -58,7 +58,7 @@ public override async Task Find(bool async) SELECT TOP(1) [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] -WHERE (@__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0)) AND [c].[CustomerID] = @__p_0"); +WHERE (@__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0) AND [c].[CustomerID] = @__p_0"); } public override async Task Materialized_query_parameter(bool async) @@ -71,7 +71,7 @@ public override async Task Materialized_query_parameter(bool async) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] -WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0)"); +WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0"); } public override async Task Materialized_query_parameter_new_context(bool async) @@ -84,14 +84,14 @@ public override async Task Materialized_query_parameter_new_context(bool async) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] -WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0)", +WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0", // @"@__ef_filter__TenantPrefix_0='T' (Size = 4000) @__ef_filter__TenantPrefix_0_1='T' (Size = 40) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] -WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0)"); +WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0"); } public override async Task Projection_query_parameter(bool async) @@ -104,7 +104,7 @@ public override async Task Projection_query_parameter(bool async) SELECT [c].[CustomerID] FROM [Customers] AS [c] -WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0)"); +WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0"); } public override async Task Projection_query(bool async) @@ -117,7 +117,7 @@ public override async Task Projection_query(bool async) SELECT [c].[CustomerID] FROM [Customers] AS [c] -WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0)"); +WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0"); } public override async Task Include_query(bool async) @@ -136,11 +136,11 @@ FROM [Orders] AS [o] LEFT JOIN ( SELECT [c0].[CustomerID], [c0].[CompanyName] FROM [Customers] AS [c0] - WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([c0].[CompanyName] IS NOT NULL) AND LEFT([c0].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0) + WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([c0].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0 ) AS [t] ON [o].[CustomerID] = [t].[CustomerID] WHERE ([t].[CustomerID] IS NOT NULL) AND ([t].[CompanyName] IS NOT NULL) ) AS [t0] ON [c].[CustomerID] = [t0].[CustomerID] -WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0)) = @__ef_filter__TenantPrefix_0) +WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0)) = @__ef_filter__TenantPrefix_0 ORDER BY [c].[CustomerID], [t0].[OrderID]"); } @@ -168,7 +168,7 @@ FROM [Orders] AS [o] LEFT JOIN ( SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] - WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0) + WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0 ) AS [t] ON [o].[CustomerID] = [t].[CustomerID] WHERE ([t].[CustomerID] IS NOT NULL) AND ([t].[CompanyName] IS NOT NULL)"); } @@ -190,7 +190,7 @@ FROM [Orders] AS [o0] LEFT JOIN ( SELECT [c].[CustomerID], [c].[CompanyName] FROM [Customers] AS [c] - WHERE @__ef_filter__TenantPrefix_1 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_1_1)) = @__ef_filter__TenantPrefix_1) + WHERE @__ef_filter__TenantPrefix_1 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_1_1)) = @__ef_filter__TenantPrefix_1 ) AS [t] ON [o0].[CustomerID] = [t].[CustomerID] WHERE ([t].[CustomerID] IS NOT NULL) AND ([t].[CompanyName] IS NOT NULL) ) AS [t0] ON [o].[OrderID] = [t0].[OrderID] @@ -214,7 +214,7 @@ FROM [Orders] AS [o] LEFT JOIN ( SELECT [c0].[CustomerID], [c0].[CompanyName] FROM [Customers] AS [c0] - WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([c0].[CompanyName] IS NOT NULL) AND LEFT([c0].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0) + WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([c0].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0 ) AS [t] ON [o].[CustomerID] = [t].[CustomerID] WHERE ([t].[CustomerID] IS NOT NULL) AND ([t].[CompanyName] IS NOT NULL) ) AS [t0] ON [c].[CustomerID] = [t0].[CustomerID] @@ -227,13 +227,13 @@ FROM [Orders] AS [o1] LEFT JOIN ( SELECT [c1].[CustomerID], [c1].[CompanyName] FROM [Customers] AS [c1] - WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([c1].[CompanyName] IS NOT NULL) AND LEFT([c1].[CompanyName], LEN(@__ef_filter__TenantPrefix_0)) = @__ef_filter__TenantPrefix_0) + WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([c1].[CompanyName], LEN(@__ef_filter__TenantPrefix_0)) = @__ef_filter__TenantPrefix_0 ) AS [t3] ON [o1].[CustomerID] = [t3].[CustomerID] WHERE ([t3].[CustomerID] IS NOT NULL) AND ([t3].[CompanyName] IS NOT NULL) ) AS [t2] ON [o0].[OrderID] = [t2].[OrderID] WHERE [o0].[Quantity] > @__ef_filter___quantity_1 ) AS [t1] ON [t0].[OrderID] = [t1].[OrderID] -WHERE (@__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0)) = @__ef_filter__TenantPrefix_0)) AND [t1].[Discount] < CAST(10 AS real)"); +WHERE (@__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0)) = @__ef_filter__TenantPrefix_0) AND [t1].[Discount] < CAST(10 AS real)"); } [ConditionalFact] @@ -254,7 +254,7 @@ public void FromSql_is_composed() FROM ( select * from Customers ) AS [m] -WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([m].[CompanyName] IS NOT NULL) AND LEFT([m].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0)"); +WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([m].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0"); } [ConditionalFact] @@ -278,7 +278,7 @@ public void FromSql_is_composed_when_filter_has_navigation() LEFT JOIN ( SELECT [c].[CustomerID], [c].[CompanyName] FROM [Customers] AS [c] - WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0) + WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0 ) AS [t] ON [m].[CustomerID] = [t].[CustomerID] WHERE ([t].[CustomerID] IS NOT NULL) AND ([t].[CompanyName] IS NOT NULL)"); } @@ -294,7 +294,7 @@ public override void Compiled_query() SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] -WHERE (@__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0)) AND [c].[CustomerID] = @__customerID", +WHERE (@__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0) AND [c].[CustomerID] = @__customerID", // @"@__ef_filter__TenantPrefix_0='B' (Size = 4000) @__ef_filter__TenantPrefix_0_1='B' (Size = 40) @@ -302,7 +302,7 @@ FROM [Customers] AS [c] SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] -WHERE (@__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0)) AND [c].[CustomerID] = @__customerID"); +WHERE (@__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0) AND [c].[CustomerID] = @__customerID"); } public override async Task Entity_Equality(bool async) @@ -318,7 +318,7 @@ FROM [Orders] AS [o] LEFT JOIN ( SELECT [c].[CustomerID], [c].[CompanyName] FROM [Customers] AS [c] - WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0) + WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0 ) AS [t] ON [o].[CustomerID] = [t].[CustomerID] WHERE ([t].[CustomerID] IS NOT NULL) AND ([t].[CompanyName] IS NOT NULL)"); } @@ -343,7 +343,7 @@ FROM [Orders] AS [o] LEFT JOIN ( SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] - WHERE @__ef_filter__TenantPrefix_0 = N'' OR (([c].[CompanyName] IS NOT NULL) AND LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0) + WHERE @__ef_filter__TenantPrefix_0 = N'' OR LEFT([c].[CompanyName], LEN(@__ef_filter__TenantPrefix_0_1)) = @__ef_filter__TenantPrefix_0 ) AS [t] ON [o].[CustomerID] = [t].[CustomerID] WHERE ([t].[CustomerID] IS NOT NULL) AND ([t].[CompanyName] IS NOT NULL)"); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindQuerySqlServerFixture.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindQuerySqlServerFixture.cs index fc42998b4ad..45288212ae3 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindQuerySqlServerFixture.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindQuerySqlServerFixture.cs @@ -54,4 +54,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con .Property(p => p.UnitPrice) .HasColumnType("money"); } + + protected override Type ContextType + => typeof(NorthwindSqlServerContext); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSetOperationsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSetOperationsQuerySqlServerTest.cs index 10fe97f8ffd..cd90efe9516 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSetOperationsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSetOperationsQuerySqlServerTest.cs @@ -273,11 +273,11 @@ public override async Task Union_with_anonymous_type_projection(bool async) FROM ( SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] - WHERE ([c].[CompanyName] IS NOT NULL) AND ([c].[CompanyName] LIKE N'A%') + WHERE [c].[CompanyName] LIKE N'A%' UNION SELECT [c0].[CustomerID], [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], [c0].[Country], [c0].[Fax], [c0].[Phone], [c0].[PostalCode], [c0].[Region] FROM [Customers] AS [c0] - WHERE ([c0].[CompanyName] IS NOT NULL) AND ([c0].[CompanyName] LIKE N'B%') + WHERE [c0].[CompanyName] LIKE N'B%' ) AS [t]"); } @@ -294,7 +294,7 @@ FROM [Customers] AS [c] SELECT [p].[ProductName] AS [CompanyName] FROM [Products] AS [p] ) AS [t] -WHERE ([t].[CompanyName] IS NOT NULL) AND ([t].[CompanyName] LIKE N'C%') +WHERE [t].[CompanyName] LIKE N'C%' ORDER BY [t].[CompanyName]"); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs index d1c08999cb1..6dfcb25bceb 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs @@ -50,14 +50,14 @@ public override async Task Where_simple_closure(bool async) var queryString = await base.Where_simple_closure(async); AssertSql( - @"@__city_0='London' (Size = 4000) + @"@__city_0='London' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] WHERE [c].[City] = @__city_0"); Assert.Equal( - @"DECLARE @__city_0 nvarchar(4000) = N'London'; + @"DECLARE @__city_0 nvarchar(15) = N'London'; SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] @@ -71,7 +71,7 @@ public override async Task Where_indexer_closure(bool async) await base.Where_indexer_closure(async); AssertSql( - @"@__p_0='London' (Size = 4000) + @"@__p_0='London' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] @@ -83,7 +83,7 @@ public override async Task Where_dictionary_key_access_closure(bool async) await base.Where_dictionary_key_access_closure(async); AssertSql( - @"@__get_Item_0='London' (Size = 4000) + @"@__get_Item_0='London' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] @@ -95,7 +95,7 @@ public override async Task Where_tuple_item_closure(bool async) await base.Where_tuple_item_closure(async); AssertSql( - @"@__predicateTuple_Item2_0='London' (Size = 4000) + @"@__predicateTuple_Item2_0='London' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] @@ -107,7 +107,7 @@ public override async Task Where_named_tuple_item_closure(bool async) await base.Where_named_tuple_item_closure(async); AssertSql( - @"@__predicateTuple_Item2_0='London' (Size = 4000) + @"@__predicateTuple_Item2_0='London' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] @@ -131,13 +131,13 @@ public override async Task Where_simple_closure_via_query_cache(bool async) await base.Where_simple_closure_via_query_cache(async); AssertSql( - @"@__city_0='London' (Size = 4000) + @"@__city_0='London' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] WHERE [c].[City] = @__city_0", // - @"@__city_0='Seattle' (Size = 4000) + @"@__city_0='Seattle' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] @@ -185,13 +185,13 @@ public override async Task Where_method_call_closure_via_query_cache(bool async) await base.Where_method_call_closure_via_query_cache(async); AssertSql( - @"@__GetCity_0='London' (Size = 4000) + @"@__GetCity_0='London' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] WHERE [c].[City] = @__GetCity_0", // - @"@__GetCity_0='Seattle' (Size = 4000) + @"@__GetCity_0='Seattle' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] @@ -203,13 +203,13 @@ public override async Task Where_field_access_closure_via_query_cache(bool async await base.Where_field_access_closure_via_query_cache(async); AssertSql( - @"@__city_InstanceFieldValue_0='London' (Size = 4000) + @"@__city_InstanceFieldValue_0='London' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] WHERE [c].[City] = @__city_InstanceFieldValue_0", // - @"@__city_InstanceFieldValue_0='Seattle' (Size = 4000) + @"@__city_InstanceFieldValue_0='Seattle' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] @@ -221,13 +221,13 @@ public override async Task Where_property_access_closure_via_query_cache(bool as await base.Where_property_access_closure_via_query_cache(async); AssertSql( - @"@__city_InstancePropertyValue_0='London' (Size = 4000) + @"@__city_InstancePropertyValue_0='London' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] WHERE [c].[City] = @__city_InstancePropertyValue_0", // - @"@__city_InstancePropertyValue_0='Seattle' (Size = 4000) + @"@__city_InstancePropertyValue_0='Seattle' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] @@ -239,13 +239,13 @@ public override async Task Where_static_field_access_closure_via_query_cache(boo await base.Where_static_field_access_closure_via_query_cache(async); AssertSql( - @"@__StaticFieldValue_0='London' (Size = 4000) + @"@__StaticFieldValue_0='London' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] WHERE [c].[City] = @__StaticFieldValue_0", // - @"@__StaticFieldValue_0='Seattle' (Size = 4000) + @"@__StaticFieldValue_0='Seattle' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] @@ -257,13 +257,13 @@ public override async Task Where_static_property_access_closure_via_query_cache( await base.Where_static_property_access_closure_via_query_cache(async); AssertSql( - @"@__StaticPropertyValue_0='London' (Size = 4000) + @"@__StaticPropertyValue_0='London' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] WHERE [c].[City] = @__StaticPropertyValue_0", // - @"@__StaticPropertyValue_0='Seattle' (Size = 4000) + @"@__StaticPropertyValue_0='Seattle' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] @@ -275,13 +275,13 @@ public override async Task Where_nested_field_access_closure_via_query_cache(boo await base.Where_nested_field_access_closure_via_query_cache(async); AssertSql( - @"@__city_Nested_InstanceFieldValue_0='London' (Size = 4000) + @"@__city_Nested_InstanceFieldValue_0='London' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] WHERE [c].[City] = @__city_Nested_InstanceFieldValue_0", // - @"@__city_Nested_InstanceFieldValue_0='Seattle' (Size = 4000) + @"@__city_Nested_InstanceFieldValue_0='Seattle' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] @@ -293,13 +293,13 @@ public override async Task Where_nested_property_access_closure_via_query_cache( await base.Where_nested_property_access_closure_via_query_cache(async); AssertSql( - @"@__city_Nested_InstancePropertyValue_0='London' (Size = 4000) + @"@__city_Nested_InstancePropertyValue_0='London' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] WHERE [c].[City] = @__city_Nested_InstancePropertyValue_0", // - @"@__city_Nested_InstancePropertyValue_0='Seattle' (Size = 4000) + @"@__city_Nested_InstancePropertyValue_0='Seattle' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] @@ -311,13 +311,13 @@ public override async Task Where_new_instance_field_access_query_cache(bool asyn await base.Where_new_instance_field_access_query_cache(async); AssertSql( - @"@__InstanceFieldValue_0='London' (Size = 4000) + @"@__InstanceFieldValue_0='London' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] WHERE [c].[City] = @__InstanceFieldValue_0", // - @"@__InstanceFieldValue_0='Seattle' (Size = 4000) + @"@__InstanceFieldValue_0='Seattle' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] @@ -329,13 +329,13 @@ public override async Task Where_new_instance_field_access_closure_via_query_cac await base.Where_new_instance_field_access_closure_via_query_cache(async); AssertSql( - @"@__InstanceFieldValue_0='London' (Size = 4000) + @"@__InstanceFieldValue_0='London' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] WHERE [c].[City] = @__InstanceFieldValue_0", // - @"@__InstanceFieldValue_0='Seattle' (Size = 4000) + @"@__InstanceFieldValue_0='Seattle' (Size = 15) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] @@ -674,7 +674,7 @@ public override async Task Where_string_indexof(bool async) AssertSql( @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] -WHERE (CAST(CHARINDEX(N'Sea', [c].[City]) AS int) - 1) <> -1 OR ([c].[City] IS NULL)"); +WHERE (CHARINDEX(N'Sea', [c].[City]) - 1) <> -1 OR ([c].[City] IS NULL)"); } public override async Task Where_string_replace(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/QueryLoggingSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/QueryLoggingSqlServerTest.cs index bc73239641b..658d0ae3114 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/QueryLoggingSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/QueryLoggingSqlServerTest.cs @@ -167,7 +167,7 @@ DbContextOptions CreateOptions(ListLoggerFactory listLoggerFactory) var loggerFactory1 = new ListLoggerFactory(); - using (var context = new NorthwindRelationalContext(CreateOptions(loggerFactory1))) + using (var context = new NorthwindSqlServerContext(CreateOptions(loggerFactory1))) { var _ = context.Customers.ToList(); } @@ -176,7 +176,7 @@ DbContextOptions CreateOptions(ListLoggerFactory listLoggerFactory) var loggerFactory2 = new ListLoggerFactory(); - using (var context = new NorthwindRelationalContext(CreateOptions(loggerFactory2))) + using (var context = new NorthwindSqlServerContext(CreateOptions(loggerFactory2))) { var _ = context.Customers.ToList(); } diff --git a/test/EFCore.SqlServer.FunctionalTests/TestModels/Northwind/NorthwindSqlServerContext.cs b/test/EFCore.SqlServer.FunctionalTests/TestModels/Northwind/NorthwindSqlServerContext.cs new file mode 100644 index 00000000000..3e14b5dfd74 --- /dev/null +++ b/test/EFCore.SqlServer.FunctionalTests/TestModels/Northwind/NorthwindSqlServerContext.cs @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.EntityFrameworkCore.TestModels.Northwind; + +public class NorthwindSqlServerContext : NorthwindRelationalContext +{ + public NorthwindSqlServerContext(DbContextOptions options) + : base(options) + { + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity( + b => + { + b.Property(e => e.EmployeeID).HasColumnType("int"); + b.Property(e => e.ReportsTo).HasColumnType("int"); + }); + + modelBuilder.Entity( + b => + { + b.Property(e => e.CustomerID).IsFixedLength(); + }); + + modelBuilder.Entity( + b => + { + b.Property(e => e.CustomerID).IsFixedLength(); + b.Property(e => e.EmployeeID).HasColumnType("int"); + b.Property(o => o.OrderDate).HasColumnType("datetime"); + }); + + modelBuilder.Entity( + b => + { + b.Property(p => p.UnitPrice).HasColumnType("money"); + b.Property(p => p.UnitsInStock).HasColumnType("smallint"); + }); + + modelBuilder.Entity( + b => + { + b.Property(p => p.UnitPrice).HasColumnType("money"); + b.Property(p => p.Quantity).HasColumnType("smallint"); + b.Property(p => p.Discount).HasColumnType("real"); + }); + } +} diff --git a/test/EFCore.Sqlite.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqliteFixture.cs b/test/EFCore.Sqlite.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqliteFixture.cs index d04ad5e16ca..2e9ea99c7c5 100644 --- a/test/EFCore.Sqlite.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqliteFixture.cs +++ b/test/EFCore.Sqlite.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesSqliteFixture.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.EntityFrameworkCore.TestModels.Northwind; + namespace Microsoft.EntityFrameworkCore.BulkUpdates; public class NorthwindBulkUpdatesSqliteFixture : NorthwindBulkUpdatesFixture @@ -8,4 +10,7 @@ public class NorthwindBulkUpdatesSqliteFixture : NorthwindBulk { protected override ITestStoreFactory TestStoreFactory => SqliteTestStoreFactory.Instance; + + protected override Type ContextType + => typeof(NorthwindSqliteContext); } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindChangeTrackingQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindChangeTrackingQuerySqliteTest.cs index 5ec71b67fb9..9154676595c 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindChangeTrackingQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindChangeTrackingQuerySqliteTest.cs @@ -14,7 +14,7 @@ public NorthwindChangeTrackingQuerySqliteTest(NorthwindQuerySqliteFixture new NorthwindRelationalContext( + => new NorthwindSqliteContext( new DbContextOptionsBuilder(Fixture.CreateOptions()) .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking).Options); } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindQueryFiltersQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindQueryFiltersQuerySqliteTest.cs index 7821a64085e..8984f3acada 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindQueryFiltersQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindQueryFiltersQuerySqliteTest.cs @@ -24,7 +24,7 @@ public override async Task Count_query(bool async) SELECT COUNT(*) FROM ""Customers"" AS ""c"" -WHERE @__ef_filter__TenantPrefix_0 = '' OR ((""c"".""CompanyName"" IS NOT NULL) AND (((""c"".""CompanyName"" LIKE @__ef_filter__TenantPrefix_0 || '%') AND substr(""c"".""CompanyName"", 1, length(@__ef_filter__TenantPrefix_0)) = @__ef_filter__TenantPrefix_0) OR @__ef_filter__TenantPrefix_0 = ''))"); +WHERE @__ef_filter__TenantPrefix_0 = '' OR ((""c"".""CompanyName"" LIKE @__ef_filter__TenantPrefix_0 || '%') AND substr(""c"".""CompanyName"", 1, length(@__ef_filter__TenantPrefix_0)) = @__ef_filter__TenantPrefix_0) OR @__ef_filter__TenantPrefix_0 = ''"); } private void AssertSql(params string[] expected) diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindQuerySqliteFixture.cs b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindQuerySqliteFixture.cs index 33e83458205..63a1806c284 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindQuerySqliteFixture.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindQuerySqliteFixture.cs @@ -19,4 +19,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con modelBuilder.Entity().Property(o => o.UnitPrice).HasConversion(); modelBuilder.Entity().Property(o => o.UnitPrice).HasConversion(); } + + protected override Type ContextType + => typeof(NorthwindSqliteContext); } diff --git a/test/EFCore.Sqlite.FunctionalTests/TestModels/Northwind/NorthwindSqliteContext.cs b/test/EFCore.Sqlite.FunctionalTests/TestModels/Northwind/NorthwindSqliteContext.cs new file mode 100644 index 00000000000..1b1f6100a44 --- /dev/null +++ b/test/EFCore.Sqlite.FunctionalTests/TestModels/Northwind/NorthwindSqliteContext.cs @@ -0,0 +1,12 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.EntityFrameworkCore.TestModels.Northwind; + +public class NorthwindSqliteContext : NorthwindRelationalContext +{ + public NorthwindSqliteContext(DbContextOptions options) + : base(options) + { + } +}