Reputation: 2028
Is there a shorter version to map the EF from the linq or lambda expression to the View Model (Movie here is the ViewModel), knowing that the EF and the ViewModel have the same fields(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);
}
}
Upvotes: 1
Views: 194
Reputation: 51504
You're looking for a mapping framework - such as AutoMapper. http://automapper.org/
Upvotes: 2