【问题标题】:IN statement in Linq [duplicate]Linq中的IN语句[重复]
【发布时间】:2017-07-05 15:33:40
【问题描述】:

谁能帮我写一下

Select * from students where studentid in 
(select studentXID from rel where parentXID = 123)

请帮帮我

提前致谢。

【问题讨论】:

  • var q = db.table.Where(x => db.rel.Any(x2 => x2.parentXID == 123 && x.studentid == x2.studentXID))

标签: sql linq asp.net-mvc-5


【解决方案1】:

在 linq 中,将这样的语句分成两部分更容易

var relList = context.rel.Where(x => x.parentXID = 123);

var result = context.students.Where(x => relList.studentXID.Contains(x.studentid));

【讨论】:

    【解决方案2】:

    这应该覆盖它

    students.Where(s => rel.Any(r => r.studentXID == s.studentid && r.studentXID == 123))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-28
      • 1970-01-01
      • 1970-01-01
      • 2017-08-10
      • 2015-09-07
      相关资源
      最近更新 更多