I am trying to make an invoice managing application.
When creating DAL object, I have to repeat Add and Delete functions for every table.
For example:
public class MyDBProcessor :IMyDBProcessor {
tpEntities tp=new tpEntities();
public void AddCustomerToDB(tblCustomers Customer) { tp.tblCustomers.Add(Customer); tp.SaveChanges();}
public void AddOrderToDB(tblOrders Order) { tp.tblOrders.Add(Order); tp.SaveChanges(); }
public tblCustomers GetCustomerFromDB(string CustomerID) { return tp.tblCustomers.Where(x => x.ID == CustomerID); }
public tblOrders GetOrderFromDB(string OrderID) { return tp.tblOrders.Where(x => x.ID == OrderID); }
}
It is very frustrating because there are so many tables. I want to change DAL interface like this:
public interface IMyGenericDBProcessor {
void AddToDB<T>(T Record);
T GetFromDB<T>(int RecordID);
}
So, when I change db engine MySQL to SQL Server or vice versa. How can I write a class that implemets IMyGenericDBProcessor?
Thank you,