namespace ContactManager.Controllers { /// <summary> /// CRUD /// </summary> /// <typeparam name="T"></typeparam> public interface IRepository<T> where T : class { IEnumerable<T> FindAll(Func<T, bool> exp); void Add(T entity); void Delete(T entity); void Save(); } public class Repository<T> : IRepository<T> where T : class { protected System.Data.Linq.DataContext m_context; public Repository(DataContext context) { m_context = context; } #region IRepository<T> Members public IEnumerable<T> FindAll(Func<T, bool> exp) { return m_context.GetTable<T>().Where(exp); } public void Add(T entity) { m_context.GetTable<T>().InsertOnSubmit(entity); } public void Delete(T entity) { m_context.GetTable<T>().DeleteOnSubmit(entity); } public void Save() { m_context.SubmitChanges(); } #endregion } public class ContactRepository : Repository<Contact> { public ContactRepository():this(new ContactManagerDataClassesDataContext()) { } public ContactRepository(DataContext context) : base(context) { } } }