Skip to content

Commit

Permalink
Stop checking store types for set operations (#30468)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers authored Mar 14, 2023
1 parent afe9bc1 commit e5b8fb4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Employee>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<InvalidOperationException>(
() => AssertQuery(
async,
ss => ss.Set<Customer>()
.Select(e => e.CompanyName)
.Union(ss.Set<Customer>().Select(e => e.ContactName))))).Message);
await AssertQuery(
async,
ss => ss.Set<Customer>()
.Select(e => e.CompanyName)
.Union(ss.Set<Customer>().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,
Expand Down

0 comments on commit e5b8fb4

Please sign in to comment.