2014-10-30 36 views
0

我想获得满足某些值的列表的记录。在Linq列表条件

var batch_institute = (from tb in context.tblBatch_Institute 
              where tb.BatchID == model.BatchID 
              select tb); 

var currentMaxBatchNo = (from tb in context.tblBatches 
               join tbins in context.tblBatch_Institute on tb.BatchID equals tbins.BatchID 
               where tb.AcadamicSemester == batch.AcadamicSemester && tb.AcadamicYear == batch.AcadamicYear 
               && tb.CampusID == batch.CampusID && tb.FacultyID == batch.FacultyID && tb.IntakeID == batch.IntakeID && 
               tb.IntakeYear == batch.IntakeYear && tb.Weekend_Day == batch.Weekend_Day 
               && batch_institute.Any(code => tbins.InstituteID.Equals(code)) 
               select tbins); 

我觉得我做的第二LINQ查询

batch_institute.Any(code => tbins.InstituteID.Equals(code)) 

我收到以下错误什么毛病下面的代码。

DbComparisonExpression需要参数相媲美类型

回答

0

第一个查询从tblBatch_Institute表返回行的集合。

但是,您尝试将行与第二个查询中的单个InstituteID值进行比较。

修改第一个查询只返回InstituteID值,如:

var batch_institute_ids = (from tb in context.tblBatch_Institute 
          where tb.BatchID == model.BatchID 
          select tb.InstituteID); 

然后下面的对比应该工作:

batch_institute_ids.Any(id => tbins.InstituteID.Equals(id)) 

您可以改变这种第二个查询使用此相反,假设EF能够将其转换为有效的SQL查询。

batch_institute_ids.Contains(tbins.InstituteID)