I use Linq-to-SQL / XML and I believe that my application has 3 levels. The difference between the pre-Linq application is that now the level of data access is much smaller and lighter, which is actually very good!
In my old DAL, I would have methods like:
public virtual int CountCustomersInCountry(string country) { // Plug in raw SQL. } public virtual List<Customer> GetCustomersInCountry(string country) { // Plug in raw SQL. } public virtual int CountCustomersForDepartment(string department) { // Plug in raw SQL. } public virtual List<Customer> GetCustomersForDepartment(string department) { // Plug in raw SQL. } etc. etc. ad-infinitum
Now I have the following methods:
public virtual int Count(Expression<Func<T, bool>> where) {
To call the new DAL methods and help DynamicLinq a bit, I use:
int countryCount = Count(c => c.Country == country); List<Customer> customers = Get(c => c.Country == country, "inserted", 0, 25); int departmentCount = Count(c => c.Department == department); List<Customer> customers = Get(c => c.Department == department, "inserted", 0, 25);
And all this before you switch to add, update and delete, which become single-line calls with Linq2SQL! My DAL now consists of 10 methods, where previously it was easy to get up to 20-30 methods for each object that DAL looked after! I highly recommend trying a hug around you as this will really save you a lot of code.
source share