One of the drawbacks about using the specification pattern is that we lose some of the functions provided by Entity Framework. Filtering the result is one of them and we will see how we can manually create the feature with the specification pattern.
Creating a Generic Repository Pattern
Relational DB - Getting Data including Data from Other Entities (Generic Repository Pattern)
Let's see how we can get data from a primary entity that has reference to other entities with the generic repository pattern Implementation Creating an Application How to create .NET web-API Setting up development tools When working with .NET, we need tool
jin-co.tistory.com
Go to the individual specification class under the core folder and add parameters to filter (in this example, 'targetId' and 'typeId') and add the code that implement the where clause in the base as shown below
: base(x =>
(!targetId.HasValue || x.ItemTargetId == targetId) &&
(!typeId.HasValue || x.ItemTypeId == typeId)
)
Go to the controller and add filtering parameters and pass that parameters to the individual specification class
Run
Move to the API folder
cd /API
And run the app
dotnet watch
In this writing, we have seen one of ways to add filtering with the specification pattern.
'Backend > .NET' 카테고리의 다른 글
Generic Repository Specification Pattern - Adding Searching (0) | 2023.04.25 |
---|---|
Generic Repository Specification Pattern - Adding Pagination (0) | 2023.04.24 |
Generic Repository Specification Pattern - Adding Sorting (0) | 2023.04.24 |
Swagger (0) | 2023.04.19 |
Using Static Files (0) | 2023.04.19 |