One of the drawbacks about using the specification pattern is that we lose some of the functions provided by Entity Framework. Searching 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
Create a class to hold the parameters as whole
Add the searching properties in the class just created
private string _search;
public string Search{
get => _search ;
set => _search = value.ToLower() ;
}
Go to the individual specification class, add the pagination class as a parameter and add the code that implement the where clause in the base as shown below
Go to the controller and add a searching parameter class and pass that parameter to the individual specification class. Note that when we use a class as a parameter the parameter will be added to the body of the request. To solve this, add '[FromQuery]' to mark it as a query
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 searching with the specification pattern.
'Backend > .NET' 카테고리의 다른 글
Packages - Identity (0) | 2023.05.01 |
---|---|
.NET - CORS (0) | 2023.04.25 |
Generic Repository Specification Pattern - Adding Pagination (0) | 2023.04.24 |
Generic Repository Specification Pattern - Adding Filtering (0) | 2023.04.24 |
Generic Repository Specification Pattern - Adding Sorting (0) | 2023.04.24 |