LINQ中的内部连接

vyswwuz2  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(80)

我想把这个SQL转移到Linq:

SELECT raoe.AreaofExpID 

     , aoe.ServiceLineID 

     , raoe.ResponseID 

  FROM AreaofExp aoe 

 INNER 

  JOIN ResponseAreaOfExp raoe 

    ON aoe.AreaofExpID = raoe.AreaofExpID 

 INNER 

  JOIN Response resp 

    ON raoe.responseid = resp.responseid 

   AND resp.segmentid = 4;

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

var query = from aoe in _cctDBContext.AreaOfExp
                    join raoe in _cctDBContext.ResponseAreaOfExp on aoe.AreaofExpId equals raoe.AreaofExpId
                    join resp in _cctDBContext.Response on raoe.ResponseId equals resp.ResponseId
                    select new
                    {
                        raoe.AreaofExp,
                        aoe.ServiceLineId,
                        raoe.ResponseId
                    };


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

envsm3lx

envsm3lx1#

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

public static class _cctDBContext
{
    public static List<AreaOfExp> AreaOfExp = new List<AreaOfExp>();
    public static List<ResponseAreaOfExp> ResponseAreaOfExp = new List<ResponseAreaOfExp>();
    public static List<Response> Response = new List<Response>();
}

public class AreaOfExp
{
    public int AreaofExpId;
    public int ServiceLineId;
}

public class ResponseAreaOfExp
{
    public int AreaofExpId;
    public int AreaofExp;
    public int ResponseId;
}

public class Response
{
    public int ResponseId;
}

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

相关问题