OK, I'm always trying to improve the way I code because it's my passion. I have a .dbml file (linq-to-sql) and I use it to access my MS SQL database.
Imagine, if you will, that you have a Person table in your database and you want to provide a way to delete,add,modify a Person record.
The way I'm handling things currently is creating classes called PersonRepository, CarRepository, DocumentRepository, etc. For each table in my database, I create a repository class.
These repository classes generally consist of something similar to this:
MyDatabaseContext db = new MyDatabaseContext();
public Person GetPersonByID(int id)
{
return db.Person.Where(p => p.ID == id);
}
Pretty much the same for the basic CRUD functionality of each table.
If I need something more specific, for example "Sergio, I need a list of all people born between x and y"; then I just add the method to the PersonRepository class.
public List<Person> GetPeopleFromDOB(DateTime x, DateTime y)
{
//Do the logic here.
}
Another idea I had was to create a DataAccess.cs class and have all of these methods in there (we would be talking around 4-5 methods per tables in existance) and have them divided by regions.
What are the more knowledgeable programmers doing and what suggestions would you offer for an eager young programmer (I'm 20 years old). Thanks so much for your time!