Home > Net >  EntityFramework. How the Core dependency injection to achieve the default search conditions to the d
EntityFramework. How the Core dependency injection to achieve the default search conditions to the d

Time:11-04

Consider the following scenario:
1, database table are set to delete id fields IS_DELETE, demands that Entityframework query data is IS_DELETE=False
2, for a list of data need to increase the default filter conditions (such as the where, in the like), in order to realize the data access control

May have the following methods (great god advice please add) :
1, set in the Context directly, but if the Context is generated, the scaffold or do the separation, this is not very flexible, high coupling,
2, use AutoMapper tools, such as filtering in transform, the problem is that I will find out all the data first, and a large quantity of data when there is a problem,
3, dependency injection, the problem is not to write, ha, ha, ha, use EntityFramework. Core 1.1 version

Welcome to the discussion

CodePudding user response:

The problem with dependency injection it doesn't matter, right?
This is a complete set of solutions

CodePudding user response:

Upgrade, and 1.1, are now 2.2, there is a QueryFilter

CodePudding user response:

Are 3.1 now have to change some configuration

CodePudding user response:

Define an interface includes IS_DELETE properties, all entities to implement the interface, and then give a IQueryable Write an extension methods, generic constraints into a previously defined interface, add filter conditions in the extension method, and then return IQueryable After the query with this extension

CodePudding user response:

Implementation in the base class for the Service you want to query interface,
  • Related