Entity Framework override SaveChanges() on Service layer instead of Data layer (different projects)

asp.net asp.net-web-api entity-framework entity-framework-6

Question

My ASP.NET WebAPI application combines many projects into a single solution for the Data & Service layer.

Data Layer (Entity Framework)
-DbContext.cs

Service Layer (Business Logic)
-Controller.cs
-Global.asax

Every time my entity does a DbContext SaveChanges, it needs business logic intercept ().

public class MyDbContext : DbContext
{

    public override int SaveChanges()
    {
        BusinessLogicAndUpdateEntity(); //Code from Service Layer
        return base.SaveChanges();
    }
}

The business logic now sits in the service layer, and data projects are unable to access service layer projects without creating a circular reference between them.

Do I have to move my business logic to the data layer in order to override DbContext SaveChanges() in the service layer?

1
0
8/26/2018 12:31:54 PM

Accepted Answer

ZZZ_tmp
2
8/25/2018 2:33:00 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow