We will create a repository:
- 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
- After that, we add two methods corresponding to the two stored procedures just created to DbContext:
-
- First, we add GetBooks:
-
- Then, we add InsertBook:
- Next, let's consume these methods: