0

I follow this tutorial: http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-4

The author uses Single method:

public ActionResult Browse(string genre)//AUTHOR'S CODE
{
    // Retrieve Genre and its Associated Albums from database
    var genreModel = storeDB.Genres.Include("Albums").Single(g => g.Name == genre);

    return View(genreModel);
}

and Find method:

public ActionResult Details(int id)//AUTHOR'S CODE
{
    var album = storeDB.Albums.Find(id);

    return View(album);
}

By analogy to Browse()(first example) method I wanted to use Single method again so I wrote:

public ActionResult Details(int id) 
{ //MY CODE
    Album album = storeDB.Albums.Single(a => a.AlbumId == id);
    return View(album);
}

Question: Does var album = storeDB.Albums.Find(id); and Album album = storeDB.Albums.Single(a => a.AlbumId == id); works in different way? The result seems to be the same.

Yoda
  • 17,363
  • 67
  • 204
  • 344

0 Answers0