Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 300 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Repository Pattern Step by Step Explanation

#1
Can someone please explain to me the Repository Pattern in .NET, step by step giving a very simple example or demo.

I know this is a very common question but so far I haven't found a satisfactory answer.
Reply

#2
As a summary, I would describe the wider impact of the repository pattern. It allows all of your code to use objects without having to know how the objects are persisted. All of the knowledge of persistence, including mapping from tables to objects, is safely contained in the repository.

Very often, you will find SQL queries scattered in the codebase and when you come to add a column to a table you have to search code files to try and find usages of a table. The impact of the change is far-reaching.

With the repository pattern, you would only need to change one object and one repository. The impact is very small.

Perhaps it would help to think about why you would use the repository pattern. Here are some reasons:

- You have a single place to make changes to your data access

- You have a single place responsible for a set of tables (usually)

- It is easy to replace a repository with a fake implementation for testing - so you don't need to have a database available to your unit tests

There are other benefits too, for example, if you were using MySQL and wanted to switch to SQL Server - but I have never actually seen this in practice!
Reply

#3
This is a nice example: [The Repository Pattern Example in C#][1]

Basically, repository hides the details of how exactly the data is being fetched/persisted from/to the database. Under the covers:

- for reading, it creates the query satisfying the supplied criteria and returns the result set
- for writing, it issues the commands necessary to make the underlying persistence engine (e.g. an SQL database) save the data


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through