CodePaste Logo
New Snippet New Recent Snippets Recent Snippets My Snippets My Snippets My Favorites Favorites Web Code Search Snippets Search
Sign inor Register
Language: csharp

Generic Repository v2

956 Views   
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Linq; namespace HelpDesk.Models { public interface IGenericRepository { IQueryable<T> Get<T>() where T : class; void Insert<T>(T item) where T : class; void Insert<T>(IEnumerable<T> items) where T : class; void Delete<T>(T item) where T : class; void Delete<T>(IEnumerable<T> items) where T : class; void Save(); } public class GenericRepository : IGenericRepository { DataContext db; public GenericRepository(DataContext dataContext) { this.db = dataContext; } public IQueryable<T> Get<T>() where T : class { return db.GetTable<T>(); } public void Insert<T>(T entity) where T : class { db.GetTable<T>().InsertOnSubmit(entity); } public void Insert<T>(IEnumerable<T> entities) where T : class { db.GetTable<T>().InsertAllOnSubmit(entities); } public void Delete<T>(T entity) where T : class { db.GetTable<T>().DeleteOnSubmit(entity); } public void Delete<T>(IEnumerable<T> entities) where T : class { db.GetTable<T>().DeleteAllOnSubmit(entities); } public void Save() { db.SubmitChanges(); } } }
by davecowart
  March 17, 2010 @ 1:49pm
Tags:
Add a comment


Report Abuse
brought to you by:
West Wind Techologies