Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Patterns for using EntityFramework?

What is alternative patterns of using for Entity Framework ?

Some I know are:

  1. "Plain" EntityFramework - aka Unity of Work

    using (Data.Model c = new Data.Model())
    {
        var z = c.Users.Where(x=>x.Name=='John');
    }

  2. Repository pattern

    //Model implements IRepository
    User user = Model.Instance.Get<User>(u => u.Name == "John");
    

  3. What else ?
  4. ?
like image 624
bug0r Avatar asked Aug 04 '09 10:08

bug0r


People also ask

Which design pattern is used for Entity Framework?

This figure shows my implementation of the DDD design pattern for handling business logic with EF Core. This also uses the separation of concerns approach, with low coupling between the business logic and the database access.

Do we need repository pattern with Entity Framework?

No, the repository/unit-of-work pattern (shortened to Rep/UoW) isn't useful with EF Core. EF Core already implements a Rep/UoW pattern, so layering another Rep/UoW pattern on top of EF Core isn't helpful.

What are the different relationship patterns in Entity Framework?

Entity framework supports three types of relationships, same as database: 1) One-to-One 2) One-to-Many, and 3) Many-to-Many.

Which design pattern is best in .NET core?

Because a developer needs to make the necessary tiers/layer himself/herself and no wonder MVC design pattern is the most popular for web development.


1 Answers

A good book to look at is Martin Fowler's "Patterns of enterprise application architecture".

There he goes through some patterns for retrieving/mapping data like DTOs, Unit of work, repository pattern etc... Maybe something could be useful together with the Entity Framework. I'd have to take a look at it.

like image 156
Juri Avatar answered Oct 27 '22 10:10

Juri