I am trying to create a generic base repository for my Linq2Sql entities. I'd like to implement a generic FindAll() method like so.
class BaseRepository<T> : IBaseRepository<T>
{
private readonly FooDataContext _ctx = new FooDataContext();
public IQueryable<T> FindAll()
{
return _ctx.T;
}
public void Add(T entity)
{
_ctx.T.InsertOnSubmit(entity);
}
public void Save()
{
_ctx.SubmitChanges();
}
}
Is there any way to do this without having to use reflection and create slowdown that would make it virtually worthless?