diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs index b8d543d91f2..1c0b5dc22b0 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs @@ -2332,15 +2332,6 @@ private void ApplySetOperation(SetOperationType setOperationType, SelectExpressi var innerColumn1 = (SqlExpression)expression1; var innerColumn2 = (SqlExpression)expression2; - // For now, make sure that both sides output the same store type, otherwise the query may fail. - // TODO: with #15586 we'll be able to also allow different store types which are implicitly convertible to one another. - if (!string.Equals( - innerColumn1.TypeMapping!.StoreType, - innerColumn2.TypeMapping!.StoreType, - StringComparison.OrdinalIgnoreCase)) - { - throw new InvalidOperationException(RelationalStrings.SetOperationsOnDifferentStoreTypes); - } // We have to unique-fy left side since those projections were never uniquified // Right side is unique already when we did it when running select2 through it. diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindQuerySqlServerFixture.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindQuerySqlServerFixture.cs index 45288212ae3..240c1a24b38 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindQuerySqlServerFixture.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindQuerySqlServerFixture.cs @@ -21,7 +21,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con b.Property(c => c.CustomerID).HasColumnType("nchar(5)"); b.Property(cm => cm.CompanyName).HasMaxLength(40); b.Property(cm => cm.ContactName).HasMaxLength(30); - b.Property(cm => cm.ContactTitle).HasColumnType("NVarChar(30)"); + b.Property(cm => cm.ContactTitle).HasColumnType("national character varying(30)"); }); modelBuilder.Entity( diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSetOperationsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSetOperationsQuerySqlServerTest.cs index 7df02c35aa5..bd94935de61 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSetOperationsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSetOperationsQuerySqlServerTest.cs @@ -1427,21 +1427,27 @@ public override async Task Client_eval_Union_FirstOrDefault(bool async) [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual async Task Union_with_different_store_types_throws(bool async) + public virtual async Task Union_with_different_store_types_is_fine_if_database_can_translate_it(bool async) { - AssertEqual( - RelationalStrings.SetOperationsOnDifferentStoreTypes, - (await Assert.ThrowsAsync( - () => AssertQuery( - async, - ss => ss.Set() - .Select(e => e.CompanyName) - .Union(ss.Set().Select(e => e.ContactName))))).Message); + await AssertQuery( + async, + ss => ss.Set() + .Select(e => e.CompanyName) + .Union(ss.Set().Select(e => e.ContactName))); + + AssertSql( +""" +SELECT [c].[CompanyName] +FROM [Customers] AS [c] +UNION +SELECT [c0].[ContactName] AS [CompanyName] +FROM [Customers] AS [c0] +"""); } [ConditionalTheory] // Issue #29020 [MemberData(nameof(IsAsyncData))] - public virtual async Task Union_with_store_types_differing_only_by_case(bool async) + public virtual async Task Union_with_type_mappings_to_same_store_type(bool async) { await AssertQuery( async,