Adding Edit ActionResult (2)

Now, we will focus on handling Edit page that being called based on Id value. The idea is finding the matched id with id in database's table, then select the list. The selected list will be stored in a new song object before it being processed.

Do you still remember LINQ to find value given condition? Yes, we use Where attribute.

How if we want to select just one value? Yes, we use SingleOrDefault attribute.

SongModel model = context.Songs.Where(some => some.Id == id).Select(some =>
                                new SongModel()
                                {
                                    Id = some.Id,
                                    Title = some.Title,
                                    Singer = some.Singer,
                                    Year = some.Year,
                                    Writer = some.Writer,
                                    GenreId = some.Id
                                }).SingleOrDefault();

results matching ""

    No results matching ""