[英]Convert sql code to linq (Inner join Query)
Could somebody help me please to convert this sql code to linq . 有人可以帮我把这个sql代码转换为linq吗?
SQL query SQL查询
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 . IN clause
中的UnitCode
动态变化并以array形式出现。 and the course code in the second part is also have variable count 第二部分的课程代码也有可变计数
Off the top of my head, assuming we have the following inputs (and you are working in C#): 假设我们有以下输入(而您使用的是C#),则无济于事:
var unitCodes = new List<string> { "FDFFSACA" ,"FDFFSCFSAA", "FDFOPTHCP3A" };
var traineeID = 10000088;
This should work: 这应该工作:
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.