Hi @sblb ,
EF Core provides the following methods to execute a stored procedure:
- Using
DbSet<TEntity>.FromSql()
Suppose there have aGetStudents
stored procedure. You can execute SP using FromSql
method in EF Core in the same way as above, as shown below.var context = new SchoolContext(); var students = context.Students.FromSql("GetStudents 'Bill'").ToList();
- Using
DbContext.Database.ExecuteSqlCommand()
Supposer this have aCreateStudents
stored procedure to insert students. Then, you could use the following code to call the SP. var context = new SchoolContext(); context.Database.ExecuteSqlCommand("CreateStudents @p0, @p1", parameters: new[] { "Bill", "Gates" });
More detail information, please check the article:Working with Stored Procedure in Entity Framework Core. Besides, you could also use the Raw SQL Queries to execute the stored procedure.
So, you can according to the Stored Procedure output data to create the entity.
Then, in the API controller, create the action method and use the above method to execute the stored procedure and get the query result. Refer to my reply in this link: ASP.NET Core 3.1 : using stored procedures with view model
Finally, in the Blazor component, use HttpClient to call the API method, and populate the textbox based on the API response data (refer to the code in the Form Create or this article: Call a web API from ASP.NET Core Blazor).
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion