具有固定值的Linq多重连接

sbdsn5lh  于 2023-07-31  发布在  其他
关注(0)|答案(1)|浏览(114)

我有以下SQL查询:

select      MFSOAM_SubAccountNbr, MFSOAM_Description, 0 as OK, MFSOAM_SubAccountNbr 
from        MFSOAM 
            left join MFSOA on MFSOA_Account=MFSOAM_SubAccountNbr 
            and MFSOA_Acc='1.1.01' 
where       MFSOA_Acc is null 
order by    OK, MFSOA.MFSOA_Account

字符串
然后我从上面的查询创建一个Linq,类似于:

var model2 = await (from a in _context.Mfsoams
                    join b in _context.Mfsoas on new { a.MfsoamSubAccountNbr } equals new { b.MfsoaAccount, jon = b.MfsoaAcc == request.Account } into ab 
                            from c in ab.DefaultIfEmpty()
                            where c.MfsoaAcc == null
                            select new
                            {
                                Acc = a.MfsoamSubAccountNbr,
                                Desc = a.MfsoamDescription,
                                OK = 0,
                                Acc2 = a.MfsoamSubAccountNbr,
                                Acc3 = c.MfsoaAcc
                            }).OrderBy(o => o.OK).ThenBy(o => o.Acc3).ToListAsync(cancellationToken);


但是join单词上有个错误,它说join子句不正确。
请指教。

  • 谢谢-谢谢
acruukt9

acruukt91#

相等的LHS与联接中相等的RHS的类型不同。
LHS类型为

class LHS
{ 
    int MfsoamSubAccountNbr {get;} 
}

字符串
RHS类型为

class RHS 
{
    int MfsoaAccount { get; }
    bool jon { get; }
}


没有明显的方法可以在这两种类型上执行EQUALS。
我猜你想

var query = from a in _context.Mfsoams
         join b in _context.Mfsoas 
         on new { Account = a.MfsoamSubAccountNbr, MfsoaAcc = request.Account } 
         equals new { Account = b.MfsoaAccount, b.MfsoaAcc } into ab 
         from c in ab.DefaultIfEmpty()
         where c.MfsoaAcc == null

相关问题