我需要返回所有事件的列表以及用户对事件可能拥有的任何回复。但是,无论我传递的用户名如何,它都会返回每个 rsvp。我的 linq 查询 ->
return (from events in this._context.Context.Events
join rsvps in (this._context.Context.RSVPs
.Where(o=> o.UserName == userName))
on events equals rsvps.Event into re
from rsvps in re.DefaultIfEmpty()
select events);
关系是
Events.EventID = RSVPs.EventID
最佳答案
from e in _context.Context.Events
join r in _context.Context.RSVPs.Where(o => o.UserName == userName)
on e.EventID equals r.EventID into g
select new {
Event = e,
Rsvps = g
};
关于c# - LINQ LEFT JOIN where 子句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15082767/