c# - Is it a good practice to add methods to the POCOs or to create separate class to update the values of the POCOs? -


is practice add methods pocos or create separate class update values of pocos in case need that?

for example,

public class foruser {     [required]     public int depratment { get; set; }      public list<selectlistitem> departmentslist { get; set; }      [required]     public int role { get; set; }      [required]     [stringlength(200, minimumlength = 3, errormessage = "length of first name should  more 3 letters")]     public string firstname { get; set; }      [stringlength(200, minimumlength = 3, errormessage = "length of mid name should  more 3 letters")]     public string midname { get; set; }      [required]     [stringlength(200, minimumlength = 3, errormessage = "length of last name should  more 3 letters")]     public string lastname { get; set; }      [required]     [emailaddress(errormessage = "invalid email address")]     public string email { get; set; }      [stringlength(14, minimumlength = 10 , errormessage = "length of mid name should  more 9 letters , less fourteen letters")]     [regularexpression(@"^[+]?[0-9]*", errormessage="phone number not correct")]     public string phonenumber { get; set; }      [required]     public string password { get; set; }       public int userid { get; set; }     public int company { get; set; }     public int country { get; set; }     public list<selectlistitem> roles { get; set; } } 

i use hold data update model entity or return data view. need update properties before send object view, list called roles in above example, wondering if should add methods poco class or better create class update properties?

here find answer question:

a poco not dto. poco stands plain old clr object, or plain old c# object. it’s .net version of pojo, plain old java object. poco business object. has data, validation, , other business logic want put in there. there’s 1 thing poco not have, , that’s makes poco. pocos not have persistence methods. if have poco of type person, can’t have person.getpersonbyid() method, or person.save() method. pocos contain data , domain logic, no persistence logic of kind. term you’ll hear concept persistence ignorance (pi). pocos persistence ignorant.

i prefer read whole article, not answer question, understand difference between poco , dto.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -