How to do it...

We will create a repository:

  1. First, we create two stored procedures in the CookBook database:
CREATE PROCEDURE [dbo].[GetBooks] ASBEGIN SET NOCOUNT ON; SELECT [Id],[Name] FROM [dbo].[Book]ENDGOCREATE PROCEDURE [dbo].[InsertBook] @name varchar(50)ASBEGIN SET NOCOUNT ON; INSERT INTO [dbo].[Book] ([Name]) VALUES (@name)ENDGO
  1. After that, we add two methods corresponding to the two stored procedures just created to DbContext:
    • First, we add GetBooks:
    • Then, we add InsertBook:
  1. Next, let's consume these methods:

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.