asp.net mvc 3.0 从数据库中读取前十个数据
publicActionResultIndex()//主页{varcommoditys=fromcinContext.Commoditysselectc;commodit...
public ActionResult Index() //主页
{
var commoditys = from c in Context.Commoditys select c;
commoditys = commoditys.Where(c => c.Category.CategoryName == "手机").OrderByDescending(c => c.CreateTime);//
if (commoditys != null)
{
return View(commoditys);
}
else
return RedirectToAction("error","home");
}
想要读取完成满足条件的前十个数据应该怎么做。???? 展开
{
var commoditys = from c in Context.Commoditys select c;
commoditys = commoditys.Where(c => c.Category.CategoryName == "手机").OrderByDescending(c => c.CreateTime);//
if (commoditys != null)
{
return View(commoditys);
}
else
return RedirectToAction("error","home");
}
想要读取完成满足条件的前十个数据应该怎么做。???? 展开
2个回答
展开全部
commoditys = commoditys.Where(c => c.Category.CategoryName == "手机").OrderByDescending(c => c.CreateTime);
//后面加上Take
commoditys = commoditys.Where(c => c.Category.CategoryName == "手机").OrderByDescending(c => c.CreateTime).Take(10);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询