c# - LINQ LEFT JOIN where 子句不起作用

标签 c# linq

我需要返回所有事件的列表以及用户对事件可能拥有的任何回复。但是,无论我传递的用户名如何,它都会返回每个 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/

相关文章:

c# - CLR 函数不会返回超过 4000 个字符

c# - 如何在基于 ASP.NET 的服务器中查询 SingleResult 对象?

c# - 在 c# 中使用 SHA 256 散列 X509 证书

c# - 最大还是默认?

c# - 包括一个集合,然后是下一级的集合

c# - 使用 LINQ 计算百分位数

c# - 我的更新查询做错了什么?

c# - oledb 导入 csv 文件 - 奇怪的字符 :˥«¿ added

c# - 错误 : An expression tree may not contain a dynamic operation

c# - 使用 LINQ 联合两个嵌套 List<object>