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

linq to sql级联查询出错
麻烦大家帮我看看这个Linq有什么错误。。刚学,新手求教,。它直接死循环了,本来有200条数据查询了100W条还在查。
return from a in db.A
  from b in db.B
  from c in db.C
  from d in db.D
  join a in db.A on a.StudentId equals B.UserID
  join d in db.D on d.GeradeID equals C.VID
  join d in db.D on d.SubjectID equals C.VID
  select new A_Ext
  {
  Title = a.Title,
  UserName=b.UserName,
  GeradeName=c.Name,
  SubjectName=c.Name,
  ViewCount=a.ViewCount,
  ReflashTime=a.ReflashTime,
  IsValid=a.IsValid
  };

------解决方案--------------------
你这是Cross join了


return from a in db.A
join b in db.B on a.StudentId equals b.UserID
join c in db.C on b.GeradeID equals c.VID
join d in db.D on d.SubjectID equals c.VID
select new A_Ext
{
Title = a.Title,
UserName=b.UserName,
GeradeName=c.Name,
SubjectName=c.Name,
ViewCount=a.ViewCount,
ReflashTime=a.ReflashTime,
IsValid=a.IsValid
};
------解决方案--------------------
return from a in db.A
from b in db.B
from c in db.C
from d in db.D
join a in db.B on a.StudentId equals B.UserID
join d in db.C on d.GeradeID equals C.VID
join d in db.C on d.SubjectID equals C.VID

------解决方案--------------------
一个一个加join吧
------解决方案--------------------
探讨

return from a in db.A
from b in db.B
from c in db.C
from d in db.D
join a in db.B on a.StudentId equals B.UserID
join d in db.C on d.GeradeID equals C.VID
join d in db.C on d.Subjec……