【问题标题】:ef core left join with "in" conditionsef core left join with "in" 条件
【发布时间】:2019-06-26 21:28:23
【问题描述】:

我有很多人的 id 我想看到组分配给这个人، 我有这样的sql查询

SELECT * 
FROM cor.[Group] AS g 
LEFT JOIN cor.PersonGroup AS pg ON 
g.Id=pg.GroupId  AND 
pg.PersonId IN (1,2)

我想为此提供 linq 查询 我写了这个 linq 查询

from g in _context.Groups join
                     pg in _context.PersonGroups.Where(pp =>personIds.Contains( pp.PersonId))
                    on g.Id equals pg.GroupId

但这和我想要的不一样

【问题讨论】:

  • @john 我对左连接“in”条件的问题
  • 好吧,我误会了。也许您可以编辑您的问题以使其更清楚?
  • @SᴇM 看来 OP 的问题在于“in”条件。
  • @Mohammadhossein 你对in 条件的确切问题是什么?

标签: c# sql-server linq


【解决方案1】:

尝试以下方法:

var persons = from grp in _context.Groups
              join pg in _context.PersonGroups on grp.Id equals pg.GroupId
              where personIds.Contains(pg.PersonId)
              select pg;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-20
    • 1970-01-01
    • 2021-09-29
    • 1970-01-01
    • 2012-07-20
    • 1970-01-01
    • 2021-11-29
    • 1970-01-01
    相关资源
    最近更新 更多