I'm reading the book "ASP.NET 3.5 Social Networking - Andrew Siemer" and I got confused when he uses Repositories to access the data.
Here is the idea of his code:
public interface IAccountRepository
{
Account GetAcountByID(int acId);
void SaveAccount(Account account);
List<Account> GetAllAccounts();
}
public class AccountRepositoryLINQ : IAccountRepository
{
Account GetAcountByID(int acId){
..... LINQ query .....
...... return.....
}
void SaveAccount(Account account){
..... LINQ .....
}
List<Account> GetAllAccounts(){
..... LINQ query .....
...... return.....
}
}
The class "Account" is the one generated automatically on the "LINQ to SQL Classes".
Some of the problems I see:
1º I code my business layer, GUI, etc... and later in time the table Accounts in the database is changed (example: change the name of one column), then I need to rebuild the "LINQ to SQL Classes" and all my code layers will need to be recoded because my "Account" object changed.
2º If I need to have other repositories (MySQL, Oracle, XML, other), what "Account" class will I use?
What to do?
- Shouldn't I use a custom Account class? This will be used in all application layers.
- How do the mapping from LINQ to my custom Account class?
- Using simple "myClass.Name = linqClass.Name;" ???
- Isn't this consuming machine resources if I need to "map" all the classes?
- There isn't a easiest/lightest way to do it?
- Is this the correct approach? Is there other ways?
- Using simple "myClass.Name = linqClass.Name;" ???