Question

How to implement repository pattern in C#.net 2.0?

Just show me the basic structure. Coz we don't have DataContext in .net 2.0.

Was it helpful?

Solution

DataContext is not a repository pattern, it's the active record pattern. Once you understand the difference between the two, you'll understand the response to your question.

Active Record is an object oriented view on of your data in the database.

A Repository is an object which live in your domain model, if you have one, this means that it's public interface is completely decoupled from your data access technology.

You use LINQ or SQL to query your database with the DataContext, and it makes sense since LINQ and SQL are very good to query data.

But when you query your Repository, since we talk more about Domain object than data, we use the Specification Pattern which is in reality a mini query language more suited to your domain.

In a nutshell, Active Record = Database and Data access, Repository = Domain model. Ideally, your customer must be able to understand the design of your Domain Model (so among other, your repository and specification classes), but he doesn't understand what a DataContext is, since it's the developer plumbing.

So to be clear, "An example of the repository pattern in C# 2.0", is not really what you should search for, "An example of the repository pattern" is, but the inner implementation will use classic ADO instead of DataContext.

OTHER TIPS

You could see an example for ASP.NET here, but I think you could understand the idea anyway.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top