CSharpFunctionalExtensions icon indicating copy to clipboard operation
CSharpFunctionalExtensions copied to clipboard

NullReference exception on Entity class

Open dataphysix opened this issue 4 years ago • 1 comments

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.

dataphysix avatar Jul 19 '21 15:07 dataphysix

Looks good, publishing this fix with v2.18.0

vkhorikov avatar Jul 19 '21 18:07 vkhorikov