![常见LINQ语句学习 常见LINQ语句学习](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
1.读取20条最新留言
public ActionResult Index()
{
var mostRecentEntries = (from entry in _db.Entries
orderby entry.DateAdded descending
select entry).Take(); ViewBag.Entries = mostRecentEntries.ToList();
return View();
}
2.搜索电影
public ActionResult SearchIndex(string searchString)
{
var movies = from m in db.Movies
select m; if (!String.IsNullOrEmpty(searchString))
{
movies = movies.Where(s => s.Title.Contains(searchString));
} return View(movies);
}