正确加入我的 linq 查询

right join on my linq query

我想要 return 来自 db.Accounts 的所有项目。 如何对以下 linq 查询进行右连接?

        var query = (
                     from tradeTbl in db.Trades
                     join acctTbl in db.Accounts on tradeTbl.AccountID equals acctTbl.AccountID

我试过改成

        var query = (
                    from acctTbl in db.Accounts
                    join tradeTbl in db.Trades on acctTbl.AccountID equals tradeTbl.AccountID
                    where acctTbl.AccountActive == true

仍然无法正常工作...如果我在 SSMS 中放入相同的查询并将其更改为 LEFT JOIN 它在 SSMS 中工作

只需通过反转联接表,按照左(外)联接来编写它。

var query =
    from a in db.Accounts
    join t in db.Trades on a.AccountID equals t.AccountID into ts
    from t in ts.DefaultIfEmpty()
    select ...;