LINQ中的内连接

  • 本文关键字:连接 LINQ linq
  • 更新时间 :
  • 英文 :


想知道是否有人可以快速帮助我转移这个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'
我相信我的第二个连接是错误的,但我不确定如何。

这是我写的代码,以获得您的查询,无需修改,工作:

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;
}

换句话说,你的查询,张贴在问题中,是好的,不包含错误。

最新更新