C# 三表上linq的左外联接
既然我有3个表要连接,并且我想从tblEvents表中获取所有数据,那么如何使用左外部连接呢C# 三表上linq的左外联接,c#,linq,C#,Linq,既然我有3个表要连接,并且我想从tblEvents表中获取所有数据,那么如何使用左外部连接呢 var response = ( from e in db.tblEvents join f in db.tblEventTypes on e.FightTypeId equals f.eventTypeId into egroup from e in egr
var response = ( from e in db.tblEvents
join f in db.tblEventTypes on e.FightTypeId equals f.eventTypeId
into egroup
from e in egroup.DefaultIfEmpty()
join w in db.tblUserWebApp on e.ModifiedUserId equals w.Id
orderby e.LastUserModified descending
select new {
FightTypeName = f.eventTypeName,
EventID = e.EventID,
FightTypeId=e.FightTypeId,
Title = e.Title,
Date = e.Date,
Location = e.Location,
UserSelectFavoriteFlag =e.UserSelectFavoriteFlag ,
Price=e.Price,
UserPredictionFlag=e.UserPredictionFlag,
PredictionStartDate= e.PredictionStartDate ,
PredictionEndDate = e.PredictionEndDate,
ModifiedUserId = w.Id,
ModifiedUser = w.LoginName,
LastUserModified = e.LastUserModified,
});
return Ok(response);
有什么问题吗??您已经使用了左外连接,我想补充一点,tblEvent具有与tblEventType和tblModified user id的内部连接,然后我希望通过左外连接从tblEvent获取所有数据
var response = ( from e in db.tblEventTypes
from f in db.tblEvents.where(x=>x.FightTypeId ==e.eventTypeId).DefaultIfEmpty()
from w in db.tblUserWebApp.where(x=>x.Id==f.ModifiedUserId)
orderby f.LastUserModified descending
select new {
FightTypeName = e.eventTypeName,
EventID = f.EventID,
FightTypeId=f.FightTypeId,
Title = f.Title,
Date = f.Date,
Location = f.Location,
UserSelectFavoriteFlag =f.UserSelectFavoriteFlag ,
Price=f.Price,
UserPredictionFlag=f.UserPredictionFlag,
PredictionStartDate= f.PredictionStartDate ,
PredictionEndDate = f.PredictionEndDate,
ModifiedUserId = w.Id,
ModifiedUser = w.LoginName,
LastUserModified = f.LastUserModified,
});