Implementing the Repository Pattern with LINQ-to-SQL
page 2 of 4
by Liam McLennan
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 29743/ 40

Repository Pattern

The Repository Pattern, according to Martin Fowler, provides a "layer of abstraction over the mapping layer where query construction code is concentrated" to "minimize duplicate query logic." In practice it is usually a collection of data access services, grouped in a similar way to the domain model classes.

By accessing repositories via interfaces, the repository pattern helps to break the dependency between the domain model and data access code. This is invaluable for unit testing because the domain model can be isolated.

I implement the repository pattern by defining one repository class for each domain model entity that requires specialized data access methods (other than the standard create, read, update and delete). If an entity does not require specialized data access methods then I will use a generic repository for that entity. A repository class contains the specialized data access methods required for its corresponding domain model entity.

The following class diagram shows an example implementation with two domain entity classes, Shape and Vertex. Shape has a specialized repository (IShapeRepository). Vertex does not have a specialized repository, so it will just use the generic repository (IRepository<Vertex>).

Figure 1

Repository Diagram


View Entire Article

User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-20 1:47:00 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search