0

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).

2 Answers 2

1

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/

Sign up to request clarification or add additional context in comments.

1 Comment

will look on it, other than this , how you implement it ? is there any blog of yours ? or some sample code or tutorial to do ? and one more thing about project hierarchy, how it should be ?
0

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...)

4 Comments

it means cant we use linq to sql ?? for generic repository ?? as i am beginner, can you help me to achive this problem, am struck with my college project
you will use linq2sql in the repository methods if you are using entityframework. if you are using nhibernate, you can use their linq to criteria methods (nhforge.org/blogs/nhibernate/archive/2009/12/17/…). the point of a generic repository is to hide the underlying data access strategy (i.e. linq2sql) from the consumer
so which is better to use Linq to sql or entity framework ? i am developing a e learning project, so considering that which i chose? can u come online ? so that i'll chat with u ..
we are chatting. i think that nhibernate is the way to go. the learning curve is a bit steeper, but the knowledge is more portable and ultimately it provides more flexiblility. if you must use a MSFT technology, i would go with entity framework.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.