I am creating an example application (MVC). I did a great job of viewing and creating a new record, but when I wrote the code to get information about a particular record, I met the following error:
Unable to cast objec`t of type 'System.Data.Objects.ObjectQuery`1[MovieApp.Models.Movie]' to type 'MovieApp.Model`s.Movie'.
here is the code i wrote to get the info
public ActionResult Details(int id) { var moviedetail = (Movie)_entities.MovieSet.Where(mvid => mvid.Id == id); return View(moviedetail); }
can any body tell me what is going wrong and where?
thank.
- Where IEnumerable, Movie. . Where extension, . , , Movie, First(), .
public ActionResult Details(int id) { var moviedetail = _entities.MovieSet.Where(mvid => mvid.Id == id).First(); return View(moviedetail); }
var moviedetail = (Movie)_entities.MovieSet.FirstOrDefault(mvid => mvid.Id == id);
Where , ToList(), , id, , , First, , match, FirstOrDefault (, null), .
Where
First
FirstOrDefault
, . . , . Single() Where() First().
var moviedetail = (Movie) _entities.MovieSet.Single (mvid => mvid.Id == id);
Source: https://habr.com/ru/post/1744144/More articles:checkstyle: disable warning ++ - eclipseI would like to access files with a specific permission in multiresolution.ico from javascript (or html, for that matter) - javascriptConvert time to decimal in .net - decimalWhat should I know to underestimate and LINQ is better? - c #Проблема с авторизацией SSPI/Kerberos на службе Windows - authorizationHow to discard all Mercurial changes that have not been committed - mercurialHow to choose LI, except the first and second? - jqueryCan a BizTalk receive port pull FailedMessageRoutings, such as a Send Port, with filtering? - biztalkHow to require CheckedListBox to have at least one selected item - vb.netIs there a way to reset all mysql databases except system databases? - mysqlAll Articles