aspnet / Templates

This repo is OBSOLETE - please see the README file for information
Other
151 stars 57 forks source link

Razor Pages scaffolder eats DbUpdateConcurrencyException #860

Closed Rick-Anderson closed 7 years ago

Rick-Anderson commented 7 years ago

Expected behavior: Scaffolder should correctly handle DbUpdateConcurrencyException

Actual behavior: DbUpdateConcurrencyException is caught and ignored.

To repro:

The Edit.cshtml.cs file contains the following code:

public async Task<IActionResult> OnPostAsync()
{
    if (!ModelState.IsValid)
    {
        return Page();
    }

    _context.Attach(Movie).State = EntityState.Modified;

    try
    {
        await _context.SaveChangesAsync();
    }
    catch (DbUpdateConcurrencyException)
    {

    }

    return RedirectToPage("./Index");
}

It should be

catch (DbUpdateConcurrencyException)
        {
            if (!MovieExists(movie.ID))
            {
                return NotFound();
            }
            else
            {
                throw;
            }
        }