0

Could somebody help me please to convert this sql code to linq .

SQL query

select distinct  coursecode
from UnitSet_Unit  
where UnitCode  in ('FDFFSACA' ,'FDFFSCFSAA', 'FDFOPTHCP3A ')
and CourseCode in (Select  distinct  coursecode
                  from Trainee_course
                  where TraineeID =10000088 )

Where UnitCode in IN clause come dynamic and in the form of array . and the course code in the second part is also have variable count

4

1 回答 1

1

假设我们有以下输入(并且您正在使用 C# 工作),我不以为然:

var unitCodes = new List<string> { "FDFFSACA" ,"FDFFSCFSAA", "FDFOPTHCP3A" };
var traineeID = 10000088;

这应该有效:

var result = (from us in db.UnitSet_Unit
              where unitCodes.Contains(us.UnitCode)
              && us.CourseCode == (from tc in db.Trainee_course
                                   where tc.TraineeID == traineeID
                                   select tc.CourseCode).Distinct().SingleOrDefault()
              select us.CourseCode).Distinct();
于 2014-10-09T14:12:26.767 回答