如何在linq中加入两个

时间:2013-05-04 11:58:18

标签: c# sql linq

我尝试将sql查询写入linq:

查询:

select s.s_name, sub.state, sub.to, sub.evaluation, sub.task_id
from submit_task sub
join student s on s.id=sub.student_id
join task t on t.id=sub.task_id
where t.t_name = "bbbb";

的LINQ:

var subTask = (from sub in ado.submit_task
               join s in ado.student on sub.student_id equals s.id
               join t in ado.task on sub.task_id equals t.id
               where t.t_name == listView3.SelectedItems[0].Text
               select new { s.s_name, sub.state, sub.to, 
                            sub.evaluation, sub.task_id });

但这不起作用。当我尝试使用dubugg时,没有任何事情发生,没有任何错误或结果。你看到了一些错误吗?

谢谢你

1 个答案:

答案 0 :(得分:1)

var text = listView3.SelectedItems[0].Text;

var subTask = (from sub in ado.submit_task
  join s in ado.student on sub.student_id equals s.id
  join t in ado.task on sub.task_id equals t.id
  where t.t_name == text
  select new { s.s_name, sub.state, sub.to, sub.evaluation, sub.task_id });