首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

linq中怎么在join中指定多个条件

2012-11-16 
linq中如何在join中指定多个条件借助于匿名类型:?public ActionResult Edit(int id)??????? {???????????

linq中如何在join中指定多个条件

借助于匿名类型:

?public ActionResult Edit(int id)
??????? {
??????????? using (DataContext db = new DataContext(ConfigurationManager.ConnectionStrings["sqlConnection"].ConnectionString))
??????????? {
??????????????? IQueryable<ClassInformation> result = from c in db.GetTable<TClass>()
????????????????????????????????????????????????????? join t in db.GetTable<TTeacher>()
????????????????????????????????????????????????????? on new { id = c.ID, id1 = c.ID }
????????????????????????????????????????????????????? equals new { id = t.ClassID, id1 = id }
????????????????????????????????????????????????????? select new ClassInformation { ID = c.ID, ClassID = t.ClassID, Name = c.Name, TeacherName = t.Name, Address = t.Address, Phone = t.Phone, Email = t.Email };
??????????????? ClassInformation k = result.Single();
??????????????? ViewData["K"] = k;
??????????????? return View();


??????????? }

??????? }

?

其实和解决按多条件分组的思路是一样的。

热点排行