efcore icon indicating copy to clipboard operation
efcore copied to clipboard

SQL Server: Set operations should work if normalized store type is the same

Open Deathrage opened this issue 3 years ago • 3 comments

In SelectExpression.cs:1594 (Microsoft.EntityFrameworkCore.Query.SqlExpression) there is code that does

if (innerColumn1.TypeMapping!.StoreType != innerColumn2.TypeMapping!.StoreType)
{
    throw new InvalidOperationException(RelationalStrings.SetOperationsOnDifferentStoreTypes);
}

If col1 type in mode is VARCHAR(20) and col2 type is varchar(20) it throws. This should not happen as SQL server is not case sensitive. I udestrand why it would be desirable for varchar(20) and varchar(50) to throw, but in case of case sensitivity it's exactly the same type.

Deathrage avatar Sep 08 '22 12:09 Deathrage

Note from triage: using the store type name is not really appropriate here. For example, it will fail to indicate that "national character varying (20)" is the same as "NVARCHAR(20)".

ajcvickers avatar Sep 09 '22 18:09 ajcvickers

I wonder if we should have a way to normalize store types, yielding their canonical representation which can be compared...

roji avatar Sep 11 '22 10:09 roji

Note from triage: fix the case-sensitivity for 7.0; punt full fix.

ajcvickers avatar Sep 13 '22 09:09 ajcvickers

When implementing store type normalization, use that also when doing parameter matching in QuerySqlGenerator.VisitSqlParameter (see https://github.com/dotnet/efcore/pull/29650#discussion_r1030251583).

roji avatar Nov 23 '22 10:11 roji

Note from design meeting: stop throwing in this case and let the database throw if the types are not compatible.

ajcvickers avatar Mar 13 '23 23:03 ajcvickers

Note for triage: we should decide what to do about parameter matching in QuerySqlGenerator.VisitSqlParameter (see https://github.com/dotnet/efcore/pull/29650#discussion_r1030251583).

ajcvickers avatar Mar 14 '23 00:03 ajcvickers

Note from triage: since the VisitSqlParameter check is an optimization only, the existing check is fine.

ajcvickers avatar Mar 16 '23 13:03 ajcvickers