是否有更短的版本可以将 EF 从 linq 或 lambda 表达式映射到 View Model(这里的Movie是 ViewModel),知道 EF 和 ViewModel 具有相同的字段(Id、Director、Plot...)?
public ActionResult MovieDetails(int ID) {
using (MAKANI.Models.Entities db = new MAKANI.Models.Entities()) {
var rMovie = (from m in db.Movies
where m.ID == ID
select new Movie {
Title = m.Title,
Director = m.Director,
Plot = m.Plot,
Link = m.Link,
Starring = m.Starring
}).Single();
return View(rMovie);
}
}