Reputation: 15861
this is i've tried so far, just learning from some blogs, i come to know how its important using generic repository, i am wondering how you people do with linq to sql, is there any good tutorial on it..
interface IBlogRepoService<T> where T:class
{
void Add(T entity);
void Delete(T entity);
T GetById(long Id);
T Get(Func<T, Boolean> where);
IEnumerable<T> GetAll();
IEnumerable<T> GetMany(Func<T, bool> where);
}
but i am gettting confused, how to implement it, different model, so is there any tutorial for generic pattern, which you people love to share.
Upvotes: 0
Views: 1664
Reputation: 15931
First you need to choose a data access package using an ORM such as Entity Framework or NHibernate will be much easier than writing your own wrapper around something like ADO. Once you've decided on the package your implementation will use, you will provide a way to interact with that package's connection to the database.
Using entity framework, your implementation will hide access to the underlying DataContext. Using nHibernate, your implementation hides details about the ISession object.
Once you understand the plumbing your implementation hides, it's pretty straight forward to map entity types (the T in your generic class definition) to the basic operations your interface provides (Add, Delete, GetById, etc...)
Upvotes: 0
Reputation: 18586
There is many examples of the repository pattern for Linq2SQL. See below for a full sample
Upvotes: 1