jasontaylordev / NorthwindTraders

Northwind Traders is a sample application built using ASP.NET Core and Entity Framework Core.
MIT License
5k stars 1.59k forks source link

ValueObject.Equals bug when objects have a different number of values #275

Closed rmatherly closed 1 year ago

rmatherly commented 4 years ago

When implementing a ValueObject that can have a variable number of values, I encountered a bug with the Equals overload in ValueObject. Because the MoveNext method is called both in the while statement and the return statement, it will return a false positive when the object on which Equals is called has one more element than the object passed in. One option to fix this would be to store the result of MoveNext for each collection in variables so they are only called once. In my case, I replaced the while loop and return statement with: return GetAtomicValues().SequenceEqual(other.GetAtomicValues()); I found this code on the Microsoft Value Object page here: https://docs.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/implement-value-objects.

jasontaylordev commented 1 year ago

Thank you for your interest in this project. This repository has been archived and is no longer actively maintained or supported. We appreciate your understanding. Feel free to explore the codebase and adapt it to your own needs if it serves as a useful reference. If you have any further questions or concerns, please refer to the README for more information.