3

我有两个表加入了这样的查询

IQueryable<Auction> closed =
                (from a in CurrentDataSource.Auctions
                 join p in CurrentDataSource.Payments
                     on a.Id equals p.AuctionId
                 where <some condition>
                 select a);

我真正想说的是给我所有没有与付款表连接或某些条件为真的拍卖。我可以用 T-SQL 做到这一点,但不知道如何用 Linq 做到这一点。你能帮我吗?

4

1 回答 1

2

您可以使用左外连接并检查付款是否为空,就像在 T-SQL 中一样。

IQueryable<Auction> closed =
                (from a in CurrentDataSource.Auctions
                 join p in CurrentDataSource.Payments
                     on a.Id equals p.AuctionId into temp
                 from t in temp.DefaultIfEmpty()
                 where t == null && <some condition>
                 select a);
于 2012-10-19T15:27:17.420 回答