Re:A todo list for new ASP.NET Core projects
by biarity on Thursday February 08, 2018 @02:06AM
(#16330719)
Well the server was going to return an error anyways, instead of checking if the entity exists then trying to create it, you just go ahead and try to create it. This way if the entity doesn't exist then you've saved a trip to the database. Otherwise you return the same error. And given the server is a black box, how would you "interrupt execution"?
[ Parent
| on HN ]
Re:A todo list for new ASP.NET Core projects
by rbobby on Thursday February 08, 2018 @05:09AM
(#16331241)
> checking if the entity exists then trying to create it,
Checking first and failing can still be problematic without the right database isolation setting.
Better to try it and catch the database error (which might include another unique constraint other than primary key... depending on db design).