Creating stored procedures

Let's create some stored procedures that our app will use to interact with the database tables:

  1. Copy the contents of the SQL Script at https://github.com/PacktPublishing/ASP.NET-Core-3-and-React-17/blob/master/Chapter07/backend/SQLScripts/02-Sprocs.sql.
  2. Click New Query to create a new SQL query and paste in the contents from the copied script.
  3. Click the Execute option on the toolbar.
  4. If we look under Stored Procedures under Programmability in Object Explorer, we should see that several stored procedures have been created:

We'll be using these stored procedures to interact with the database from the ASP.NET Core app.

  1. Before we finish this section, let's try to run one of the stored procedures. Click New Query to create a new SQL query and enter the following:
EXEC dbo.Question_GetMany_BySearch @Search = 'type'

So, this SQL command will execute the Question_GetMany_BySearch stored procedure passing in the @Search parameter with a value of type. This stored procedure returns questions that have the value of the @Search parameter in the title or its content.

  1. Click the Execute option on the toolbar and we should get the following results:

With our SQL Server database in place, we can now turn our attention to Dapper.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.254.179