79076553

Date: 2024-10-11 01:27:17
Score: 0.5
Natty:
Report link

I worked out eventually that the reason it isn't working is because EF Core only updates the entity with the auto-incremented ID if the ID in the model is the default value for the type. The default value for EntityId is null, so the value of 0 I had given it told EF Core that it didn't need to be updated.

The best solution I have found to this so far is to create a backing field for the EntityId and assign to to a primitive type (int in this instance). Since EF Core does not allow null primary keys, this was all I could come up with at this stage.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Keyan