I am new to repository pattern but i tried, my goal is to make a design which will let me easily with just some few edits "dependency injection, or configuration edits" to be able to switch to another ORM without touching other solution layers.
I reached this implementation:
and here is the code:
public interface IRepository<T>
{
T Get(int key);
IQueryable<T> GetAll();
void Save(T entity);
T Update(T entity);
// Common data will be added here
}
public interface ICustomerRepository : IRepository<Customer>
{
// Specific operations for the customers repository
}
public class CustomerRepository : ICustomerRepository
{
#region ICustomerRepository Members
public IQueryable<Customer> GetAll()
{
DataClasses1DataContext context = new DataClasses1DataContext();
return from customer in context.Customers select customer;
}
#endregion
#region IRepository<Customer> Members
public Customer Get(int key)
{
throw new NotImplementedException();
}
public void Save(Customer entity)
{
throw new NotImplementedException();
}
public Customer Update(Customer entity)
{
throw new NotImplementedException();
}
#endregion
}
usage in my aspx page:
protected void Page_Load(object sender, EventArgs e)
{
IRepository<Customer> repository = new CustomerRepository();
var customers = repository.GetAll();
this.GridView1.DataSource = customers;
this.GridView1.DataBind();
}
As you saw in the previous code i am now using LINQ to sql, and as you see my code is tied to LINQ to sql, how to change this code design to achieve my goal "be able to change to another ORM easly, for example to ADO.net entity framework, or subsonic"
Please advice with simple sample code