不要加入Linq

不要加入Linq,linq,Linq,我有两个表,我在这样的查询中加入了它们 IQueryable<Auction> closed = (from a in CurrentDataSource.Auctions join p in CurrentDataSource.Payments on a.Id equals p.AuctionId where <some conditi

我有两个表,我在这样的查询中加入了它们

IQueryable<Auction> closed =
                (from a in CurrentDataSource.Auctions
                 join p in CurrentDataSource.Payments
                     on a.Id equals p.AuctionId
                 where <some condition>
                 select a);
IQueryable已关闭=
(来自CurrentDataSource.Auctions中的
在CurrentDataSource.Payments中加入p
a.Id等于p.AuctionId
哪里
选择a);

我真正想说的是,如果没有加入付款表或某些条件为真,请给出所有拍卖。我可以用T-SQL实现这一点,但不知道如何用Linq实现。您能帮忙吗?

您可以使用左外部联接并检查付款是否为空,就像在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);
IQueryable已关闭=
(来自CurrentDataSource.Auctions中的
在CurrentDataSource.Payments中加入p
在a.Id上等于p.AuctionId到temp
来自临时DefaultIfEmpty()中的t
其中t==null&&
选择a);

这里的连接条件不是只提供匹配的行吗?@SachinKainth这是左外部连接的语法,当与
t==null
条件组合时,将只提供没有关联付款的拍卖。请参见此处的LINQ left外部联接文档:发布您的工作sql有助于转换