Skip to content

Call a stored procedure and map the result for an ASP.NET Core App

Notifications You must be signed in to change notification settings

swastiks/StoredProcedureDotNetCore

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to call a stored procedure in an ASP.NET core app

This code add a static method to DbContext named ExecuteStoredProcedure. The latter calls a stored procedure and maps the result into an enumerable of the specified type. If the model type is not specified, it will return a boolean gotten from the SQL Server return statement.

using (var context = new DataAccess.TestContext())
{
    IEnumerable<ResultModel> res = context.ExecuteStoredProcedure<ResultModel>("[dbo].[StoredProcedureName]", ("param_name", value));
}

Useful files are:

  • DataAccessBase.cs shows how to call a stored procedure
  • DbTools.cs contains the method ExecuteStoredProcedure and AutoMap

Why ?

This repository was made in response of the following Entity Framework's issues :

About

Call a stored procedure and map the result for an ASP.NET Core App

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 94.2%
  • SQLPL 5.8%