Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Edited Issue: EntityFramework CRUD scaffolding template incorrectly uses Single() [251]

$
0
0
The templated Delete action for an "API controller with read/write actions, using Entity Framework" produces the following code:

Platform platform = db.Platforms.Single(p => p.Id == id);
if (platform == null)
{
return Request.CreateResponse(HttpStatusCode.NotFound);
}

If I'm not mistaken, Single will throw on a null/no elements in sequence, and so the null check in the 2nd line will never run and the 404 will not be returned.

The template needs to be updated to use SingleOrDefault.

Thanks!

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>