【发布时间】:2015-12-11 14:54:22
【问题描述】:
在 where 子句中为 orderby 获取此错误。我这样做是因为以前,如果我没有定义“人”,我会在返回时收到错误,因为人们说“人”这个名字在当前上下文中不存在。我该如何解决这个问题?
public JsonResult PersonsList(string birthyear)
{
TutorialDBContext db = new TutorialDBContext();
var NumericYear = Convert.ToInt32(birthyear);
IQueryable people;
if (birthyear == "All")
{
people = from m in db.persons
select m;
people = people.OrderByDescending(s => s.birthdate);
}
else
{
people = from m in db.persons
where m.birthdate.Year >= NumericYear
where m.birthdate.Year <= (NumericYear + 9)
select m;
}
return Json(people, JsonRequestBehavior.AllowGet);
}
【问题讨论】:
标签: c# .net linq iqueryable