diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs index cb631152c70..30ea9c5f5eb 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs @@ -134,6 +134,11 @@ protected override Expression VisitExtension(Expression extensionExpression) return CreateShapedQueryExpression(entityType, queryExpression); + case QueryRootExpression queryRootExpression + when queryRootExpression.EntityType.GetSqlQueryMappings().FirstOrDefault(m => m.IsDefaultSqlQueryMapping)?.SqlQuery is ISqlQuery querySql: + return Visit(new FromSqlQueryRootExpression( + queryRootExpression.EntityType, querySql.Sql, Expression.Constant(Array.Empty(), typeof(object[])))); + default: return base.VisitExtension(extensionExpression); } diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindKeylessEntitiesQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindKeylessEntitiesQueryCosmosTest.cs index 07e4c1d2c1c..86fe1805405 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindKeylessEntitiesQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindKeylessEntitiesQueryCosmosTest.cs @@ -88,6 +88,12 @@ FROM root c WHERE ((c[""Discriminator""] = ""Customer"") AND (c[""City""] = ""London""))"); } + [ConditionalTheory(Skip = "Issue #17246")] + public override Task KeylessEntity_with_included_nav(bool async) + { + return base.KeylessEntity_with_included_nav(async); + } + public override async Task KeylessEntity_with_defining_query(bool async) { await base.KeylessEntity_with_defining_query(async); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindQueryCosmosFixture.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindQueryCosmosFixture.cs index dd7146e7711..e38584b1bf2 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindQueryCosmosFixture.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindQueryCosmosFixture.cs @@ -38,17 +38,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con modelBuilder .Entity() .HasDiscriminator("Discriminator").HasValue("Customer"); - -#pragma warning disable CS0618 // Type or member is obsolete - modelBuilder - .Entity().Metadata.SetDefiningQuery(null); - modelBuilder - .Entity().Metadata.SetDefiningQuery(null); - modelBuilder - .Entity().Metadata.SetDefiningQuery(null); - modelBuilder - .Entity().Metadata.SetDefiningQuery(null); -#pragma warning restore CS0618 // Type or member is obsolete } } } diff --git a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindChangeTrackingQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindChangeTrackingQueryInMemoryTest.cs index 6f8a2d3abea..7a40d9bdcfc 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindChangeTrackingQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindChangeTrackingQueryInMemoryTest.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Microsoft.EntityFrameworkCore.TestModels.Northwind; using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit.Abstractions; @@ -13,5 +14,10 @@ public NorthwindChangeTrackingQueryInMemoryTest(NorthwindQueryInMemoryFixture new NorthwindInMemoryContext( + new DbContextOptionsBuilder(Fixture.CreateOptions()) + .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking).Options); } } diff --git a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindInMemoryContext.cs b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindInMemoryContext.cs new file mode 100644 index 00000000000..a8bbf485b5a --- /dev/null +++ b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindInMemoryContext.cs @@ -0,0 +1,58 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Linq; +using Microsoft.EntityFrameworkCore.TestModels.Northwind; + +namespace Microsoft.EntityFrameworkCore.Query +{ + public class NorthwindInMemoryContext : NorthwindContext + { + public NorthwindInMemoryContext(DbContextOptions options) + : base(options) + { + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + InMemoryEntityTypeBuilderExtensions.ToQuery( + modelBuilder.Entity(), + () => Customers.Select( + c => new CustomerQuery + { + Address = c.Address, + City = c.City, + CompanyName = c.CompanyName, + ContactName = c.ContactName, + ContactTitle = c.ContactTitle + })); + + InMemoryEntityTypeBuilderExtensions.ToQuery( + modelBuilder.Entity(), + () => Orders.Select(o => new OrderQuery { CustomerID = o.CustomerID })); + + InMemoryEntityTypeBuilderExtensions.ToQuery( + modelBuilder.Entity(), + () => Products.Where(p => !p.Discontinued) + .Select( + p => new ProductQuery + { + ProductID = p.ProductID, + ProductName = p.ProductName, + CategoryName = "Food" + })); + + InMemoryEntityTypeBuilderExtensions.ToQuery( + modelBuilder.Entity(), + () => Customers.Select( + c => new CustomerQueryWithQueryFilter + { + CompanyName = c.CompanyName, + OrderCount = c.Orders.Count(), + SearchTerm = SearchTerm + })); + } + } +} diff --git a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindKeylessEntitiesQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindKeylessEntitiesQueryInMemoryTest.cs index 94855a0eb33..4ae6fb911f6 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindKeylessEntitiesQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindKeylessEntitiesQueryInMemoryTest.cs @@ -1,7 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; using Xunit.Abstractions; namespace Microsoft.EntityFrameworkCore.Query @@ -26,5 +29,11 @@ public override void KeylessEntity_by_database_view() public override void Entity_mapped_to_view_on_right_side_of_join() { } + + public override async Task KeylessEntity_with_included_nav(bool async) + { + await Assert.ThrowsAsync(() => base.KeylessEntity_with_included_nav(async)); + } + } } diff --git a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindQueryInMemoryFixture.cs b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindQueryInMemoryFixture.cs index 47b1c7592a3..766ed5d14d4 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/NorthwindQueryInMemoryFixture.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/NorthwindQueryInMemoryFixture.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.TestUtilities; @@ -10,5 +11,7 @@ public class NorthwindQueryInMemoryFixture : NorthwindQueryFix where TModelCustomizer : IModelCustomizer, new() { protected override ITestStoreFactory TestStoreFactory => InMemoryTestStoreFactory.Instance; + + protected override Type ContextType => typeof(NorthwindInMemoryContext); } } diff --git a/test/EFCore.InMemory.FunctionalTests/Query/QueryBugsInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/QueryBugsInMemoryTest.cs index 792a052ce71..0a7e52125a8 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/QueryBugsInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/QueryBugsInMemoryTest.cs @@ -709,9 +709,8 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder) { -#pragma warning disable CS0618 // Type or member is obsolete - modelBuilder.Entity().HasNoKey().ToQuery(Build_Customers_Sql_View_InMemory()); -#pragma warning restore CS0618 // Type or member is obsolete + InMemoryEntityTypeBuilderExtensions.ToQuery( + modelBuilder.Entity().HasNoKey(), Build_Customers_Sql_View_InMemory()); } private Expression>> Build_Customers_Sql_View_InMemory() diff --git a/test/EFCore.Relational.Specification.Tests/Query/InheritanceQueryRelationalFixture.cs b/test/EFCore.Relational.Specification.Tests/Query/InheritanceQueryRelationalFixture.cs index ec7e9c2dccf..baabec3108c 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/InheritanceQueryRelationalFixture.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/InheritanceQueryRelationalFixture.cs @@ -32,10 +32,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con modelBuilder.Entity().Property(e => e.SugarGrams).HasColumnName("SugarGrams"); modelBuilder.Entity().Property(e => e.CaffeineGrams).HasColumnName("CaffeineGrams"); -#pragma warning disable CS0618 // Type or member is obsolete - modelBuilder.Entity().HasNoKey().ToQuery( - () => context.Set().FromSqlRaw("SELECT * FROM Animals")); -#pragma warning restore CS0618 // Type or member is obsolete + modelBuilder.Entity().HasNoKey().ToQuerySql("SELECT * FROM Animals"); modelBuilder.Entity().HasDiscriminator().HasValue("Kiwi"); modelBuilder.Entity().HasDiscriminator().HasValue("Eagle"); } diff --git a/test/EFCore.Relational.Specification.Tests/TestModels/Northwind/NorthwindRelationalContext.cs b/test/EFCore.Relational.Specification.Tests/TestModels/Northwind/NorthwindRelationalContext.cs index ff0decc59bd..593dcab6692 100644 --- a/test/EFCore.Relational.Specification.Tests/TestModels/Northwind/NorthwindRelationalContext.cs +++ b/test/EFCore.Relational.Specification.Tests/TestModels/Northwind/NorthwindRelationalContext.cs @@ -12,7 +12,6 @@ public NorthwindRelationalContext(DbContextOptions options) { } - public string _empty = string.Empty; protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -27,23 +26,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity().HasKey(coh => coh.ProductName); modelBuilder.Entity().HasKey(mep => mep.TenMostExpensiveProducts); -#pragma warning disable CS0618 // Type or member is obsolete - modelBuilder.Entity().HasNoKey().ToQuery( - () => CustomerQueries.FromSqlInterpolated( - $"SELECT [c].[CustomerID] + {_empty} as [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]" - )); - - modelBuilder - .Entity() - .HasNoKey() - .ToQuery( - () => Orders - .FromSqlRaw(@"select * from ""Orders""") - .Select( - o => new OrderQuery { CustomerID = o.CustomerID })); -#pragma warning restore CS0618 // Type or member is obsolete - - modelBuilder.Entity().HasNoKey().ToView("Alphabetical list of products"); + modelBuilder.Entity().ToQuerySql("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]"); + + modelBuilder.Entity().ToQuerySql(@"select * from ""Orders"""); + modelBuilder.Entity().ToView("Alphabetical list of products"); } } } diff --git a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs index e92711a852b..b0fd6ba5044 100644 --- a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs +++ b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs @@ -60,7 +60,7 @@ public void Model_differ_does_not_detect_views_with_weak_types() } [ConditionalFact] - public void Model_differ_does_not_detect_queries() + public void Model_differ_does_not_detect_defining_queries() { DbContext context = null; Execute( @@ -72,6 +72,15 @@ public void Model_differ_does_not_detect_queries() result => Assert.Empty(result)); } + [ConditionalFact] + public void Model_differ_does_not_detect_queries() + { + Execute( + _ => { }, + modelBuilder => modelBuilder.Entity().HasNoKey().ToQuerySql("SELECT * FROM Vista"), + result => Assert.Empty(result)); + } + [ConditionalFact] public void Model_differ_detects_adding_store_type() { diff --git a/test/EFCore.Specification.Tests/Query/NorthwindKeylessEntitiesQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindKeylessEntitiesQueryTestBase.cs index 8d90ac4e520..982af1e7fb4 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindKeylessEntitiesQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindKeylessEntitiesQueryTestBase.cs @@ -70,7 +70,7 @@ var results .Where(cq => cq.OrderCount > 0) .ToArray(); - Assert.Equal(4, results.Length); + Assert.Equal(89, results.Length); } [ConditionalTheory] @@ -82,7 +82,7 @@ public virtual Task KeylessEntity_with_defining_query(bool async) ss => ss.Set().Where(ov => ov.CustomerID == "ALFKI")); } - [ConditionalTheory] + [ConditionalTheory(Skip = "Issue#21828")] [MemberData(nameof(IsAsyncData))] public virtual Task KeylessEntity_with_defining_query_and_correlated_collection(bool async) { @@ -111,46 +111,30 @@ from o in ss.Set().Where(ov => ov.CustomerID == c.CustomerID) [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task KeylessEntity_with_included_nav(bool async) - { - using var ctx = CreateContext(); - if (async) - { - await Assert.ThrowsAsync( - () => (from ov in ctx.Set().Include(ov => ov.Customer) - where ov.CustomerID == "ALFKI" - select ov).ToListAsync()); - } - else - { - await Assert.ThrowsAsync( - () => Task.FromResult( - (from ov in ctx.Set().Include(ov => ov.Customer) - where ov.CustomerID == "ALFKI" - select ov).ToList())); - } + public virtual Task KeylessEntity_with_included_nav(bool async) + { + return AssertQuery( + async, + ss => from ov in ss.Set().Include(ov => ov.Customer) + where ov.CustomerID == "ALFKI" + select ov, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(ov => ov.Customer)), + entryCount: 1); } - [ConditionalTheory] + [ConditionalTheory(Skip = "Issue#21828")] [MemberData(nameof(IsAsyncData))] - public virtual async Task KeylessEntity_with_included_navs_multi_level(bool async) - { - using var ctx = CreateContext(); - if (async) - { - await Assert.ThrowsAsync( - () => (from ov in ctx.Set().Include(ov => ov.Customer.Orders) - where ov.CustomerID == "ALFKI" - select ov).ToListAsync()); - } - else - { - await Assert.ThrowsAsync( - () => Task.FromResult( - (from ov in ctx.Set().Include(ov => ov.Customer.Orders) - where ov.CustomerID == "ALFKI" - select ov).ToList())); - } + public virtual Task KeylessEntity_with_included_navs_multi_level(bool async) + { + return AssertQuery( + async, + ss => from ov in ss.Set().Include(ov => ov.Customer.Orders) + where ov.CustomerID == "ALFKI" + select ov, + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(ov => ov.Customer), + new ExpectedInclude(c => c.Orders, "Customer")), + entryCount: 1); } [ConditionalTheory] diff --git a/test/EFCore.Specification.Tests/TestModels/Northwind/NorthwindContext.cs b/test/EFCore.Specification.Tests/TestModels/Northwind/NorthwindContext.cs index a7b8ba2f898..a03fee989bc 100644 --- a/test/EFCore.Specification.Tests/TestModels/Northwind/NorthwindContext.cs +++ b/test/EFCore.Specification.Tests/TestModels/Northwind/NorthwindContext.cs @@ -74,67 +74,17 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) od => new { od.OrderID, od.ProductID }); }); -#pragma warning disable CS0618 // Type or member is obsolete - modelBuilder - .Entity() - .HasNoKey() - .ToQuery( - () => Customers - .Select( - c => new CustomerQuery - { - Address = c.Address, - City = c.City, - CompanyName = c.CompanyName, - ContactName = c.ContactName, - ContactTitle = c.ContactTitle - })); - - modelBuilder - .Entity() - .HasNoKey() - .ToQuery( - () => Orders - .Select( - o => new OrderQuery { CustomerID = o.CustomerID })); - - modelBuilder - .Entity() - .HasNoKey() - .ToQuery( - () => Products - .Where(p => !p.Discontinued) - .Select( - p => new ProductQuery - { - ProductID = p.ProductID, - ProductName = p.ProductName, - CategoryName = "Food" - })); - - modelBuilder - .Entity() - .HasNoKey() - .HasQueryFilter(cq => cq.CompanyName.StartsWith(_searchTerm)) - .ToQuery( - () => - Customers - .Include(c => c.Orders) // ignored - .Select( - c => - new CustomerQueryWithQueryFilter - { - CompanyName = c.CompanyName, - OrderCount = c.Orders.Count(), - SearchTerm = _searchTerm - })); -#pragma warning restore CS0618 // Type or member is obsolete + modelBuilder.Entity().HasNoKey(); + modelBuilder.Entity().HasNoKey(); + modelBuilder.Entity().HasNoKey(); + modelBuilder.Entity().HasNoKey(); + modelBuilder.Entity().HasNoKey(); } public string TenantPrefix { get; set; } = "B"; private readonly short _quantity = 50; - private readonly string _searchTerm = "A"; + public readonly string SearchTerm = "A"; public void ConfigureFilters(ModelBuilder modelBuilder) { @@ -146,6 +96,7 @@ public void ConfigureFilters(ModelBuilder modelBuilder) modelBuilder.Entity().HasQueryFilter(od => EF.Property(od, "Quantity") > _quantity); modelBuilder.Entity().HasQueryFilter(e => e.Address.StartsWith("A")); modelBuilder.Entity().HasQueryFilter(p => ClientMethod(p)); + modelBuilder.Entity().HasQueryFilter(cq => cq.CompanyName.StartsWith(SearchTerm)); } private static bool ClientMethod(Product product) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindKeylessEntitiesQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindKeylessEntitiesQuerySqlServerTest.cs index 00d9c12a201..89c2591b4dd 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindKeylessEntitiesQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindKeylessEntitiesQuerySqlServerTest.cs @@ -25,7 +25,7 @@ public override async Task KeylessEntity_simple(bool async) await base.KeylessEntity_simple(async); AssertSql( - @"SELECT [c].[CustomerID] + N'' as [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]"); + @"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]"); } [ConditionalTheory] @@ -36,7 +36,7 @@ public override async Task KeylessEntity_where_simple(bool async) AssertSql( @"SELECT [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle] FROM ( - SELECT [c].[CustomerID] + N'' as [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] + 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] ) AS [c] WHERE [c].[City] = N'London'"); } @@ -50,6 +50,7 @@ public override void KeylessEntity_by_database_view() FROM [Alphabetical list of products] AS [a]"); } + [ConditionalFact(Skip = "Issue#21627")] public override void KeylessEntity_with_nav_defining_query() { base.KeylessEntity_with_nav_defining_query(); @@ -143,7 +144,7 @@ public override void Auto_initialized_view_set() base.Auto_initialized_view_set(); AssertSql( - @"SELECT [c].[CustomerID] + N'' as [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]"); + @"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]"); } public override async Task KeylesEntity_groupby(bool async) @@ -153,7 +154,7 @@ public override async Task KeylesEntity_groupby(bool async) AssertSql( @"SELECT [c].[City] AS [Key], COUNT(*) AS [Count], COALESCE(SUM(CAST(LEN([c].[Address]) AS int)), 0) AS [Sum] FROM ( - SELECT [c].[CustomerID] + N'' as [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] + 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] ) AS [c] GROUP BY [c].[City]"); } @@ -177,7 +178,7 @@ public override async Task Collection_correlated_with_keyless_entity_in_predicat SELECT TOP(@__p_0) [c].[City], [c].[ContactName] FROM ( - SELECT [c].[CustomerID] + N'' as [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] + 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] ) AS [c] WHERE EXISTS ( SELECT 1 diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs index 87e31dbaf5e..ea62a51132f 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs @@ -1384,7 +1384,7 @@ LEFT JOIN ( FROM ( SELECT [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], ROW_NUMBER() OVER(PARTITION BY [c0].[CompanyName] ORDER BY (SELECT 1)) AS [row] FROM ( - SELECT [c].[CustomerID] + N'' as [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] + 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] ) AS [c0] ) AS [t] WHERE [t].[row] <= 1 diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs index ba6bcb06bff..6c7d6bad293 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs @@ -4434,13 +4434,9 @@ public MyContext13346(DbContextOptions options) protected override void OnModelCreating(ModelBuilder modelBuilder) { -#pragma warning disable CS0618 // Type or member is obsolete modelBuilder.Entity() .HasNoKey() - .ToQuery( - () => Set() - .FromSqlRaw("SELECT o.Amount From Orders AS o")); -#pragma warning restore CS0618 // Type or member is obsolete + .ToQuerySql("SELECT o.Amount From Orders AS o"); } } diff --git a/test/EFCore.SqlServer.FunctionalTests/WithConstructorsSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/WithConstructorsSqlServerTest.cs index 33df5078bfd..6f10c9b3a82 100644 --- a/test/EFCore.SqlServer.FunctionalTests/WithConstructorsSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/WithConstructorsSqlServerTest.cs @@ -25,10 +25,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con { base.OnModelCreating(modelBuilder, context); -#pragma warning disable CS0618 // Type or member is obsolete - modelBuilder.Entity().HasNoKey().ToQuery( - () => context.Set().FromSqlRaw("SELECT * FROM Blog")); -#pragma warning restore CS0618 // Type or member is obsolete + modelBuilder.Entity().HasNoKey().ToQuerySql("SELECT * FROM Blog"); } } } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindKeylessEntitiesQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindKeylessEntitiesQuerySqliteTest.cs index 0b2f1636444..d3b832f3f8f 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindKeylessEntitiesQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindKeylessEntitiesQuerySqliteTest.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; using Xunit.Abstractions; namespace Microsoft.EntityFrameworkCore.Query @@ -14,5 +15,11 @@ public NorthwindKeylessEntitiesQuerySqliteTest(NorthwindQuerySqliteFixture().HasNoKey().ToQuery( - () => context.Set().FromSqlRaw("SELECT * FROM Blog")); -#pragma warning restore CS0618 // Type or member is obsolete + modelBuilder.Entity().HasNoKey().ToQuerySql("SELECT * FROM Blog"); } } }