In project I have the class - model class (call this class - modelClass
).
And I have a class (call this class - dbClass
) which provide some methods for work with database (db - Advantage database architecture). This class provide static methods for work with database. I know that I can use some ORM(like EF), repository pattern, but in this project the main idea for work with database this is static class with static methods.
In modelClass I have thi field - "Status
" (string type).
My use-case is update record in database when I set the filed "Status
".
You can see my solution below:
public class modelClass{
//here some fileds
public string Status { get; set; }
//here some fileds
}
public class dbClass{
//here some fileds and method for work with database
public static void update(modelClass mClass){
//here update the record in database
}
}
using
....
modelClass.Status = "status";
dbClass.update(modelClass);
....
I came up with another solution.
The idea of my decision is to use keyword "set
".
Let me explain my idea - when I set the field in modelClass I want to set field and update record in database.
For example:
public class modelClass{
//here some fileds
private string Status { get; set; }
//create public setter
public string setStatus{
get { return Status; }
set
{
Status = value;
dbClass.update(this);
}
}
//here some fileds
}
using
modelClass.setStatus= "status";
The main questions is:
- Is it good practice work with database by setter?
- Why I should/shouldn't use this idea?
- Please explain me main pros and cons of my idea