Backend/.NET

Generic Repository Specification Pattern - Adding Searching

Jin-Co 2023. 4. 25. 16:41
반응형

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.

 

728x90
반응형