开发者

Recommended IRepository and IRepository<T> interface in C#

I am looking for a simple IRepository interface for my mvc web application, I have done a lot of searching a开发者_如何转开发round, and there are as many opinions as there are people. So i decided to ask the experts

If you can recommend a IRepository and IRepository interfaces that are commonly used and answer the basic CRUD and query operations ( to support filtering ).

If you know of frameworks that also include implementations and can work with EF 4 I would love if you can mention them.

Thank you.

Edit: As @Ladislav suggests what is the alternative, always just call linq to ADO.net calls from my code? Is it a good idea to use a POCO repository that abstract creation of custom POCOS from my business model, I have a Jewel POCO class that need to be parsed from varies DB entries, is this a common practice with legacy systems where I can't touch the DB architecture but only the presentation


Stop. Patterns should be used when they are needed - when they solve some common problem - not because they exist. You obviously don't need it at the moment because you didn't write any single requirement what the repository should solve for you - such requirements are crucial if you want to choose a "good one" to start with. Anyway a good one usually evolve during your development, it is most often not defined upfront.

Also generic repository with EF is one of the most stupid patterns I have ever used in my own project. It is good only to be parent of specific repository. It works only in basic scenarios where you most often don't need repository at all.

Something to read: What is the point of generic repository


The repository pattern is pretty straight-forward...you really don't need to use an existing framework. You can build the interface(s) yourself. There are a number of good examples out there in blogs of people building their own and also allows them to have near 100% code coverage in their tests. Here's a few examples (but they all follow similar patterns):

Using Repository Pattern with Entity Framework (Gil Fink)

100% UNIT TESTABLE LINQ TO SQL REPOSITORY (Kazi Manzur Rashid) -- I'm actually following some of his examples in my work

Working together: LINQ to SQL, IRepository, Unit Of Work and Dependency Injection (Stuart Harris)

And there are a ton more.

I think building it yourself, especially if you're just learning the pattern, will definitely teach you a ton about the pattern and also give you insight into what works for your situation and what doesn't.

I hope this helps! Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜