Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop checking store types for set operations #30468

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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