炫意html5
最早CSS3和HTML5移动技术网站之一

如何查看控制台中linq生成的SQL

List<Teacher> teachers = new List<Teacher> {
new Teacher(“徐老师”,
new List<Student>(){
new Student(“宋江”,80),
new Student(“卢俊义”,95),
new Student(“朱武”,45)
}
),
new Teacher(“姜老师”,
new List<Student>(){
new Student(“林冲”,90),
new Student(“花荣”,85),
new Student(“柴进”,58)
}
),
new Teacher(“樊老师”,
new List<Student>(){
new Student(“关胜”,100),
new Student(“阮小七”,70),
new Student(“时迁”,30)
}
)
};
var query1 = from t in teachers
from s in t.Students
where s.Score < 60
select new
{
t,
teacherName = t.Name,
student = t.Students.Where(p => p.Score < 60).ToList()
};
foreach (var item in query1)
{
Console.WriteLine(“老师姓名:” + item.teacherName + “,学生姓名:” + item.student.FirstOrDefault().Name + “,成绩:” + item.student.FirstOrDefault().Score);
}
1.我在控制台中写了linq语句,如何才能查看该linq语句生成的SQL语句呢?
2.该条linq语句中为什么要对学生成绩做两次筛选呢?

回答

  1. 试试 query1.ToString()

炫意HTML5 » 如何查看控制台中linq生成的SQL

Java基础教程Android基础教程