SQL “WHERE IN” query conversion to LINQ

前端 未结 1 1703
天涯浪人
天涯浪人 2021-01-23 21:07

I\'m trying to find a way to convert this very complex SQL Query into LINQ and I can\'t seem to tackle all the embedded \"WHERE IN\" clauses. Would someone be so kind as to len

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-23 21:44

    You convert the SQL IN statement to linq with either Contains or Any

    Contains

    from dv in db.Device
    where
      (from au in db.Audit
      where au.AuditDate >= DateTime.Now.AddMonths(-3)
      select au.AccountID).Contains(dv.AccountID)
    

    Any

    from dv in db.Device
    where 
       db.Audit.Any(au => au.AuditDate >= DateTime.Now.AddMonths(-3) && 
                    au.AccountID == dv.AccountID)
    

    0 讨论(0)
提交回复
热议问题