如何通过linq在联接语句中使用两个条件



我试图向我的联接添加两个条件,但我做不到。我使用||运算符。

from pay in db.Payments
join FlyRpt in db.FlightReportTickets 
on pay.ObjectIdDepartue equals FlyRpt.DepartureId ||
   FlyRpt.DepartureId equals pay.ObjectIdReturn
join prof in db.Profiles on FlyRpt.UserId equals prof.UserId
where pay.ReserveType == 1 &&
    pay.Transactionsuccess &&
    pay.IssueDate >= fromDateTime &&
    pay.IssueDate <= toDateTime
select new
{
    FlyRpt.FullPrice
};

如果要在join:中实现OR,则需要使用where

from pay in db.Payments
from FlyRpt in db.FlightReportTickets
where pay.ObjectIdDepartue == FlyRpt.DepartureId
|| FlyRpt.DepartureId == pay.ObjectIdReturn
join prof in db.Profiles on FlyRpt.UserId equals prof.UserId
where pay.ReserveType == 1 &&
pay.Transactionsuccess &&
pay.IssueDate >= fromDateTime &&
pay.IssueDate <= toDateTime
select new
{
    FlyRpt.FullPrice,
};

您可以使用交叉联接,因为您不能在其他联接中使用OR

from pay in db.Payments
from FlyRpt in db.FlightReportTickets 
where 
    pay.ObjectIdDepartue = FlyRpt.DepartureId ||
    FlyRpt.DepartureId equals pay.ObjectIdReturn
join prof in db.Profiles 
on FlyRpt.UserId equals prof.UserId
where 
    pay.ReserveType == 1 &&
    pay.Transactionsuccess &&
    pay.IssueDate >= fromDateTime &&
    pay.IssueDate <= toDateTime
select new
{
    FlyRpt.FullPrice,
};

相关内容

  • 没有找到相关文章

最新更新