.net core 升级到6以后使用Union查询的问题

var qry = (
from item in _context.Table1
select new SomeModel
{
Name = "A"
}
)
.Union
(
from item in _context.Table2
select new SomeModel
{
Name = item.UserName
}
).ToList();

查询抛出异常:Unable to translate set operation when matching columns on both sides have different store types.

这是什么原因?UserName也是string类型,为什么无法转换?2.1版本并不会出现这样的问题。

回答

算是一个已知的bug:https://github.com/dotnet/efcore/issues/24707

解决办法:Name = item.UserName.ToString()

以上是.net core 升级到6以后使用Union查询的问题的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>