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

Strict data type comparision when using concat results in Unable to translate set operation when matching columns on both sides have different store types #28528

Closed
Panuf opened this issue Jul 27, 2022 · 2 comments

Comments

@Panuf
Copy link

Panuf commented Jul 27, 2022

When concating two queries which have different precise data type (ie. varchar(max) vs varchar(50)) there is exception:
"Unable to translate set operation when matching columns on both sides have different store types.'".

   at Microsoft.EntityFrameworkCore.Query.SqlExpressions.SelectExpression.ApplySetOperation(SetOperationType setOperationType, SelectExpression select2, Boolean distinct)
   at Microsoft.EntityFrameworkCore.Query.SqlExpressions.SelectExpression.ApplyUnion(SelectExpression source2, Boolean distinct)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateConcat(ShapedQueryExpression source1, ShapedQueryExpression source2)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Sample.UnitTest.ConcatConstantString() in C:\Projects\Sample\Sample\UnitTest.cs:line 26

Example could be constant value in one query and db column in second, but I would assume same problem can occure when combining queries that are based on different columns:

DbContextOptions<SampleContext> options = new DbContextOptions<SampleContext>();
            SampleContext databaseContext = new SampleContext(options);
            IQueryable<Projection> first = (from items in databaseContext.Items
                                             select new Projection()
                                             {
                                                 Id1 = items.Id,
                                                 Name1 = "First"
                                             });

            IQueryable<Projection> second = (from items in databaseContext.Items
                                             select new Projection()
                                             {
                                                 Id1 = items.Id,
                                                 Name1 = items.Name
                                             });

            IList<Projection> result = first.Concat(second).ToList();

Include provider and version information

EF Core version: 6.0.7
Database provider: SqlServer
Target framework: .NET 6.0
Sample.zip

@Panuf Panuf changed the title Strict data type comparision when using concat Strict data type comparision when using concat results in Unable to translate set operation when matching columns on both sides have different store types Jul 27, 2022
@roji
Copy link
Member

roji commented Jul 27, 2022

Duplicate of #19129

@roji roji marked this as a duplicate of #19129 Jul 27, 2022
@Panuf
Copy link
Author

Panuf commented Jul 27, 2022

Thank You.

@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants