快速概述后,如果我有几个嵌套的内连接,我没有找到如何处理linq到sql。
这就是我想要的linq
SELECT Booking.BookingId, Booking.EventId, Booking.StartDate, Event.Name, Person.FirstName
FROM Booking
INNER JOIN Event
INNER JOIN Asset
ON Asset.AssetId = Event.AssetId
INNER JOIN Person
ON Person.PersonId = Event.ContactPersonId
ON Event.EventId = Booking.EventId AND Event.State = 4
有谁知道如何将其翻译成LINQ? 谢谢。
答案 0 :(得分:1)
var q1= from a in booking,b in event,c in asset, d in person where a.eventid=b.eventid and b.state=4 and c.assetid = b.assetid and b.contactpersonid=d.personid select a,b,c,d
你可以用你想要的列名替换a,b,c,d
另一种方法是使用join关键字:
var w1= from a in booking join b in event on a.eventid equals b.eventid join c in asset on ...
答案 1 :(得分:0)
var query = from b in context.Bookings
from e in context.Events
join a in context.Assets on e.AssetId equals a.AssetId
join p in context.People on e.ContactPersonId equals p.PersonId
where e.State == (byte)States.Approved && e.EventId == b.EventId
select new { EventName = e.Name, BookingDate = b.StartDate };