vkhorikov/CSharpFunctionalExtensions

Id on Entity class should be private.

xavierjohn opened this issue · 3 comments

It is normal for domain entity class to not have an Id so making Id public exposes a property that makes no sense to the domain.

Example. StudentNumber is the key for Student entity. It makes sense to declare the class as


class Student:Entity
{
      public StudentNumber;
      public Name;

      ctor(string studentNumber, string name) : base(studentNumber)
     {
         this.StudentNumber = studentNumber;
          this.Name = name;
     }
}

If this class was used for storage with EF, it will not try to persist Id, if Id was made private. Having a public Id forces all domain entities to have Id which violates the domain purity.

Your email is full.

vlad@enterprisecraftsmanship.com
Remote Server returned '552 5.2.2 Mailbox size limit exceeded 1625158722-JlfT9WQJrE-wfMG6cAk'

Remote Server returned '552 5.2.2 Mailbox size limit exceeded 1625158722-JlfT9WQJrE-wfMG6cAk'

This is very strange. Thanks much for letting me know, it should be working now.

Regarding Ids. Using natural Ids (such as StudentNumber) is sub-optimal. It assumes that the identity of the student is defined by their number, which it shouldn't be. An entity shouldn't be defined by any of its properties; it should be surrogate -- something that isn't tied to the real world.