我在这样的查询中加入了两个表
IQueryable<Auction> closed =
(from a in CurrentDataSource.Auctions
join p in CurrentDataSource.Payments
on a.Id equals p.AuctionId
where <some condition>
select a);
我真正想要的是说给我所有的拍卖,其中 IS NO 加入Payments表或某些条件为真。我可以用T-SQL做到这一点,但不知道如何用Linq做到这一点。你能帮忙吗?
答案 0 :(得分: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);