I am trying to write a generic repository that will perform basic methods on all my linq2sql classes. (getById, insert, delete, getAll)
Im not so sure on how to get this done. Heres what I got so far... the getById method is giving me an error cause it cant relate Id attribute to 'T' class. I would appreciate some pointers on how to wrap my head around this generic class concept
public class Repository<T> where T:class
{
private ClassesDataContext db = new ClassesDataContext();
public IQueryable<T> getAll()
{
return db.GetTable<T>();
}
public T getById(int id)
{
db.GetTable<T>().Where(e=>e.Id==id);
return db.GetTable<T>().Single(c =>c.Id==id);
}}