When running the program, the error prompt is:
Unable to translate set operation when matching columns on both sides have different store types
reason:
When the union method is used for database query, the field types of the two queries are inconsistent, resulting in
Example code:
var list = (from d in ctx.Employee
select new
{
d.Id,
AmountOfMoney = 0,
}).Union(from v in ctx.Product
select new
{
v.Id,
d.AmountOfMoney,
}
);
Wrong interpretation:
There is no accountofmoney field in the employee table. We give a default value of 0. The system defaults to int type
Amountofmoney in the product table is the decimal type
At this time, the compilation will report an error. We add a cast type to the field of employee, as follows
var list = (from d in ctx.Employee
select new
{
d.Id,
AmountOfMoney = (decimal)0,
//or AmountOfMoney = 0M,
}).Union(from v in ctx.Product
select new
{
v.Id,
d.AmountOfMoney,
}
);
The result is still an error. Maybe the latest grammar doesn’t support this writing method
Similar Posts:
- [Solved] org.springframework.dao.DataIntegrityViolationException: Error attempting to get column…
- [Solved] Cause: java.sql.SQLException: The used SELECT statements have a different number of columns
- Error in modifying data element data type [How to Solve]
- [Solved] Postgre Error: ERROR: UNION types numeric and character varying cannot be matched
- [Solved] MySQL ERROR 1054 (42S22): Unknown column ‘i2goods.t_ebook_data.fbookid’ in ‘field list’
- [Solved] Oracle :value too large for column “SCHEMA”.”TABLE”.”COLUMN” (actual: 519, maximum: 500)
- MYSQL Incorrect usage of UNION and ORDER BY [How to Solve]
- [Solved] BigDecimal division error: Non-terminating decimal expansion; no exact representable decimal result.
- Linux Programmer Error: /bin/bash: No such file or directory [How to Solve]
- [Solved] Division Error: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.