Skip to content

Example of repository pattern for C# and .NET Core 2

Notifications You must be signed in to change notification settings

gabrielmdc/csharp-repository-pattern

Repository files navigation

Repository Pattern in c# and Entity Framework

This is an example of Repository Pattern using Entity Framework

File structure (the most relevant):

  • models
  • repositories
    • IRepository
    • IMyRepository
    • Repository
    • MyRepository
  • MyContext.cs
  • MyContextFactory.cs
  • UnitOfWork.cs

Run

Step 1

To run this example, you must have a database (remember to adapt the connection string from the file global.json) and a table with the follow structure:

create table treatment
(
    treatmentid int identity primary key,
    treatmenttext varchar(100),
    -- description of the treatment
    price int,
)

Step 2

Intstall dependencies:

dotnet restore

Step 3

Compile and run (from the root path of the project):

dotnet run

About

Example of repository pattern for C# and .NET Core 2

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages