CSharpFunctionalExtensions
CSharpFunctionalExtensions copied to clipboard
NullReference exception on Entity class
I stumbled upon an issue with the Entity class. This happened in a desktop application where a collection of entities can be added to and removed from a list before persisting them to the database. I consider these as entities in a transient state. When the Remove(T item) method on the List<T> is called the Equals method causes the exception. The issues is easily reproduceable:
[Fact]
public void Two_different_entities_with_nullable_id_are_not_equal()
{
MyEntityWithStringId entity1 = MyEntityWithStringId.Create();
MyEntityWithStringId entity2 = MyEntityWithStringId.Create();
(entity1 == entity2).Should().BeFalse();
}
public class MyEntityWithStringId : Entity<string>
{
public static MyEntityWithStringId Create()
{
return new MyEntityWithStringId();
}
}
I will create a pull request with the fix.
Looks good, publishing this fix with v2.18.0