Data Source - Best way to organize methods / classes relevant to the entire table?

4

In my company we work with models based on the standard "Active Record", that is, the methods of the model are always referring to the operations of a single record of the database, for example:

Class User {
    int id;
    string Name;

    public Find (id); // SQL / ORM to return the object based on the user's Id;
    public Save (); // SQL / ORM to save / update a user
    public Delete (); // SQL / ORM to delete a user.
}

// Create the user "John"
Set objUser = new User ();
objUser.Name = "John";
objUser.Save ();

My question is as follows, regarding the entity of the database "User", we have methods that are at table level and not record level, such as a "getAllActiveUsers" method, which returns me an object of query of all active users. This type of situation today, due to a lack of standard ends up in the model ActiveRecord itself, which in my opinion does not make much sense .. Could you tell me what would be the most recommendable / elegant to treat this type of situation? I read something about Gateway and Repository Pattern that might be useful for this, but I wanted to know if anyone else has had this same dilemma and how did they solve it ..

Thank you and sorry for ignorance!

    
asked by anonymous 23.07.2015 / 17:23

1 answer

1

In my opinion, the "save itself" object in the database does not make sense, regardless of whether you use pure ADO or some ORM, I think the Repository pattern is more appropriate; but of course everything depends on the scenario.

I recommend that you look at this tutorial by Eduardo Pires, he takes a step by step and explains some patterns and how to implement them, it may not be the solution to all your problems, but you will start to have a new vision and from there think of your own architecture:

/ a>

I hope I have helped.

    
28.07.2015 / 14:51