日期:2014-05-20  浏览次数:21052 次

LINQ嵌套查询
public ActionResult Show()
            {
                IEnumerable<Show> model = from  o in _db.CourseOrder.ToList<CourseOrder>()
                                         select new Show
                                          {
                                             Classname = from s in _db.Classes where s.Classno == o.Classno select s.Classname ,
                                             UseTime = o.UseTime,
                                             Roomno = o.Roomno,
                                             Cname = from p in _db.Courses where p.Cno == o.Cno select p.Cname,
                                              Tname = from q in _db.Teachers where q.Tno == o.Tno select q.Tname 
                                          };
                return View(model);
            }
怎么实现LINQ嵌套查询啊?这些语句怎么都实现不了?Classname = from s in _db.Classes where s.Classno == o.Classno select s.Classname ,
Cname = from p in _db.Courses where p.Cno == o.Cno select p.Cname,
                                              Tname = from q in _db.Teachers where q.Tno == o.Tno select q.Tname 
纠结好久了,求了解的人帮帮忙,谢谢
------解决方案--------------------
本帖最后由 q107770540 于 2013-10-11 21:43:32 编辑
 
 IEnumerable<Show> model = from  o in _db.CourseOrder 
                           select new Show
                           {
                               Classname = _db.Classes.Single(s=> s.Classno == o.Classno).Classname ,   
                               UseTime = o.UseTime,
                               Roomno = o.Roomno,
                               Cname =_db.Courses.Single(p=> p.Cno == o.Cno).Cname, 
                               Tname =_db.Teachers.Single(q=>q.Tno == o.Tno).Tname