Skip to main content

290 posts tagged with ".NET"

.NET Framework and Core for Application Development

View All Tags

How to Return 409 Conflict for a Duplicate Key with EF Core and MySQL

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

When a unique index refuses a value, EF Core throws an exception, and your API answers 500. But nothing broke: the client asked for something that already exists, and 409 Conflict is the right answer. This guide reads MySQL's error number from the exception, and catches only that error, with a small helper you can reuse.

How to Use a Concurrency Token in EF Core with MySQL

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

When two people edit the same row, the second save overwrites the first, and nobody finds out. A concurrency token fixes this: a column that changes with every update, and that EF Core adds to the WHERE of each UPDATE. If it changed since you read the row, the update finds nothing, and you can tell the client. This guide adds one on MySQL.