C# 在mvc中将sql查询更改为linq

C# 在mvc中将sql查询更改为linq,c#,sql,linq,C#,Sql,Linq,我想使用join语句将sql查询更改为linq。查询应检索列(days和startdate),同时将表1的记录与表1的记录进行匹配。简而言之,使用join语句将sql查询转换为linq 下面是我试过的 SQL查询(工作) LINQ(不获取结果) 如果您的EF实体定义良好,您可以通过以下方式简化查询: var result = Db.Batches .Include(p => p.StudentBatchRelation) .Whe

我想使用join语句将sql查询更改为linq。查询应检索列(
days
startdate
),同时将表1的记录与表1的记录进行匹配。简而言之,使用join语句将sql查询转换为linq

下面是我试过的

SQL查询(工作)

LINQ(不获取结果)


如果您的EF实体定义良好,您可以通过以下方式简化查询:

var result = Db.Batches
               .Include(p => p.StudentBatchRelation)
               .Where(p => p.StudentBatchRelation.StudentId = "3d980306-e36e-4581-8c98-219717cb1668")
               .ToList();
否则,如果必须使用
Getallxxxx
函数,则可以执行以下操作:

var result = (from t1 in contBatch.GetallBatchList()
              join t2 in contStudent.getAllStudentBatchList()
                     on t1.Id equals t2.batchId 
              where t2.studentId == "3d980306-e36e-4581-8c98-219717cb1668"
              select t1)
              .ToList();

try不带selectA查询必须以select子句或组结束clause@user100020,尝试选择新的{t1,t2}如果你看我的问题,我做了同样的事情。你是否有错误?你的答案与我在问题中提到的答案类似。
var result = Db.Batches
               .Include(p => p.StudentBatchRelation)
               .Where(p => p.StudentBatchRelation.StudentId = "3d980306-e36e-4581-8c98-219717cb1668")
               .ToList();
var result = (from t1 in contBatch.GetallBatchList()
              join t2 in contStudent.getAllStudentBatchList()
                     on t1.Id equals t2.batchId 
              where t2.studentId == "3d980306-e36e-4581-8c98-219717cb1668"
              select t1)
              .ToList();