LINQ中的内部连接

vyswwuz2  于 2024-01-03  发布在  其他
关注(0)|答案(1)|浏览(222)

我想把这个SQL转移到Linq:

  1. SELECT raoe.AreaofExpID
  2. , aoe.ServiceLineID
  3. , raoe.ResponseID
  4. FROM AreaofExp aoe
  5. INNER
  6. JOIN ResponseAreaOfExp raoe
  7. ON aoe.AreaofExpID = raoe.AreaofExpID
  8. INNER
  9. JOIN Response resp
  10. ON raoe.responseid = resp.responseid
  11. AND resp.segmentid = 4;

字符串
经过这方面的工作,我得到了这个:

  1. var query = from aoe in _cctDBContext.AreaOfExp
  2. join raoe in _cctDBContext.ResponseAreaOfExp on aoe.AreaofExpId equals raoe.AreaofExpId
  3. join resp in _cctDBContext.Response on raoe.ResponseId equals resp.ResponseId
  4. select new
  5. {
  6. raoe.AreaofExp,
  7. aoe.ServiceLineId,
  8. raoe.ResponseId
  9. };


现在我得到一个错误:
需要上下文关键字“on”
我相信我的第二个连接是错误的,但我不知道如何。

envsm3lx

envsm3lx1#

下面是我写的代码,让你的查询,没有修改,工作:

  1. public static class _cctDBContext
  2. {
  3. public static List<AreaOfExp> AreaOfExp = new List<AreaOfExp>();
  4. public static List<ResponseAreaOfExp> ResponseAreaOfExp = new List<ResponseAreaOfExp>();
  5. public static List<Response> Response = new List<Response>();
  6. }
  7. public class AreaOfExp
  8. {
  9. public int AreaofExpId;
  10. public int ServiceLineId;
  11. }
  12. public class ResponseAreaOfExp
  13. {
  14. public int AreaofExpId;
  15. public int AreaofExp;
  16. public int ResponseId;
  17. }
  18. public class Response
  19. {
  20. public int ResponseId;
  21. }

字符串
换句话说,您的查询,如问题中所张贴的,是好的,不包含错误。

展开查看全部

相关问题