entity framework - Allow exception when inserting record with or check and short circuit first? -


for httppost operation object being inserted has alternate key, considered best option handling database conflict when inserting?

should check if entity exists first , return error code there conflict

    if (reportingcontext.reports.any(r => r.reportid == report.reportid))     {         return new httpstatuscoderesult(statuscodes.status409conflict);     } 

should allow operation go through, allowing successful addition database if there no conflict, or exception thrown if there conflict?

what worse? 2 calls database, 1 check if entity exists , second insert new entity... or overhead of creating new entity in memory , assigning properties, have exception out because there conflict? burden on database vs needless burden on server?


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -