gpt4 book ai didi

c# - EF 联盟问题“无法从

转载 作者:太空宇宙 更新时间:2023-11-03 12:28:14 25 4
gpt4 key购买 nike

这应该是一个简单的联合查询,但即使操作类型相同,它也会抛出一个错误:

Instance argument: cannot convert from System.Linq.IQueryable<AnonymousType#1> to System.Linq.ParallelQuery<AnonymousType#2>

如果我删除此列,则它工作正常。在第一次选择中,我想将操作值分配给“0”。任何帮助表示赞赏。谢谢

(from p in Pages join pa in PageAct on p.PageId equals pa.PageId
select new
{
PageId = p.PageId,
PgName = p.PgName,
ActionId = pa.ActionId,
ActionName = pa.ActionName,
**action = 0**
}).Union(from p in Pages
join pa in PageAct on p.PageId equals pa.PageId
join rp in RolePerm on pa.ActionId equals rp.ActionId into jrs
from jrResult in jrs.DefaultIfEmpty()
where jrResult.RoleId == 1
select new
{
PageId = p.PageId,
PgName = p.PgName,
ActionId = pa.ActionId,
ActionName = pa.ActionName,
action = jrResult.ActionId
})

最佳答案

匿名对象应具有完全相同的签名才能被视为相同。

如果 RolePerm.ActionId 是可空类型,则第一个匿名对象属性类型也应该是可空的。实际类型也可以是不可空的,但由于这是左连接,您不应忘记显式转换为可空 int,否则您可能会遇到运行时异常。

(from p in Pages join pa in PageAct on p.PageId equals pa.PageId
select new
{
PageId = p.PageId,
PgName = p.PgName,
ActionId = pa.ActionId,
ActionName = pa.ActionName,
action = (int?)0
}).Union(from p in Pages
join pa in PageAct on p.PageId equals pa.PageId
join rp in RolePerm on pa.ActionId equals rp.ActionId into jrs
from jrResult in jrs.DefaultIfEmpty()
where jrResult.RoleId == 1
select new
{
PageId = p.PageId,
PgName = p.PgName,
ActionId = pa.ActionId,
ActionName = pa.ActionName,
action = (int?)jrResult.ActionId // should cast, even if ActionId is not nullable
// because left join might give null
})

关于c# - EF 联盟问题“无法从 <AnonymusType#1 转换为 AnonymusType#2>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43797976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com