Ravi Gadag
Ravi Gadag

Reputation: 15861

asp.net mvc3 with Generic repository pattern LInq to sql

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.

  1. i want to know how should be the project hierarchy for asp.net mvc3, (linq to sql with generic repository pattern).

Upvotes: 0

Views: 1664

Answers (2)

Jason
Jason

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

LiamB
LiamB

Reputation: 18586

There is many examples of the repository pattern for Linq2SQL. See below for a full sample

http://www.codefrenzy.net/2011/10/06/a-generic-implementation-of-the-repository-pattern-for-linq-to-sql/

Upvotes: 1

Related Questions