79209690

Date: 2024-11-21 04:36:20
Score: 0.5
Natty:
Report link

TL;DR - I implement the GetHashCode method wrong for ValueObject.

After creating a different project to test out the User and ChangePasswordCode, I find out that the problem lies in the UserId value object as it works fine when I use Guid as the primary key. At that time, I suspect that the change tracker may compare the 2 UserId in User and ChangePasswordCode entries and somehow doesn't match the 2. So the problem could be in the Equals and GetHashCode method that I implement for ValueObject.

By placing breakpoints in debug mode, I find out that the change tracker indeed calls the GetHashCode first before the Equals and it returns 2 different hash codes for the same UserId. I fix the GetHashCode method and it works now.

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