Share via

Unable to translate set operation when matching columns on both sides have different store types

权达 罗 1 Reputation point
2022-07-04T11:46:09.407+00:00

(
from item in _context.Table1
select new SomeModel
{
Name ="A"
}
)
.Union
(
from item in _context.Table2
select new SomeModel
{
Name = Convert.ToString(item.UserName)
}
)
it is not work,and throw out:Unable to translate set operation when matching columns on both sides have different store types.
Why?

Developer technologies | .NET | Other
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 83,986 Reputation points
    2022-07-05T01:32:03.443+00:00

    the linq expression must be converted to sql. The Convert function is not supported. if using a late enough version .ToString() should work:

    Name = item.UserName.ToString()

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.