0

RPM1984 in this question speaks about POCO are "persistent ignorant" objects. But he doen´t speak about how much logic can hold. For example:

class Person {
    public string FirstName { get; set; }
}

Or this:

class Person {
    private string firstName = string.Empty;

    public string Firstname {
        get 
        { 
            return this.firstname; 
        }
        set { 
            if (value.Length > 26)
            {
                throw new System.ComponentModel.DataAnnotations.ValidationException("Firstname is too long");
            }
            this.firstname = value;
        }
    }
}

Both are "persistent igonrant". The first one is for sure a POCO class. But is it the second a valid POCO? It has some logic but it could be persisted without problem and its logic is not more than a validation. Can it be considered POCO?

Thanks

Community
  • 1
  • 1

1 Answers1

0

Yes, the second one is a valid POCO, because it doesn't use a persistence specific detail. The whole point of POCOs is to say that a certain object doesn't depend on a db access library. If, for example, you would decorate Person with an EF specific attribute then, you would have to reference EF everywhere you'd use that class.

MikeSW
  • 16,140
  • 3
  • 39
  • 53