class Program { static void Main(string[] args) { //Linq创建的数据库上下文对象db DataClasses2DataContext db = new DataClasses2DataContext(); //表连接查询,从Student表和Score表中根据Sno相同查Sno,Sname,Cno,Degree //相当于select Student.Sno,Sname,Cno,Degree from Studet,Score where Student.Sno = Score.Sno var list = from s in db.Student join c in db.Score on s.Sno equals c.Sno select new { Sno = s.Sno, Sname = s.Sname, Cno = c.Cno, Degree = c.Degree }; foreach (var l in list) { Console.WriteLine(l.Sno + " | " + l.Sname + " | " + l.Cno + " | " + l.Degree); } Console.ReadLine(); } }