A simple ASP.NET Core Web API project demonstrating how to call SQL Server stored procedures using Entity Framework Core.
- ASP.NET Core Web API (.NET 6+)
- Entity Framework Core with SQL Server
- Calls stored procedures using
FromSqlRaw
andFromSqlInterpolated
- Clean folder structure (Controllers, Models, Services, Data)
- Dependency Injection for DbContext and services
- API endpoint to fetch employees by department and status
StoredProcWebAPI/ │ ├── Controllers/ # API endpoints ├── Models/ # Data models (e.g., Employee.cs) ├── Services/ # Business logic (e.g., EmployeeService.cs) ├── Data/ # AppDbContext and EF config ├── appsettings.json # Connection string ├── Program.cs # Service registration and app config └── README.md # Project info (this file)
- ASP.NET Core Web API
- Entity Framework Core
- SQL Server (Stored Procedures)
- .NET 6 or later
git clone https://github.com/Amir-dev-net/aspnetcore-api-sqlproc.git cd aspnetcore-api-sqlproc
Update your connection string in appsettings.json:
"ConnectionStrings": { "DefaultConnection": "Server=.;Database=YourDbName;Trusted_Connection=True;" }
dotnet restore
dotnet run Visit: http://localhost:5000/swagger
🧪 Sample API Endpoint Get Employees by Department & Status
GET /api/employees/by-department/{deptId}/status/{isActive} Example:
GET /api/employees/by-department/2/status/true
🧩 Stored Procedure Sample CREATE PROCEDURE sp_GetEmployeesByDeptAndStatus @DepartmentId INT, @IsActive BIT AS BEGIN SELECT Id, Name, Department FROM Employees WHERE DepartmentId = @DepartmentId AND IsActive = @IsActive END
📄 License This project is open-source and available under the MIT License.
🙌 Credits Created by [AMIR HAMZA] Inspired by clean, maintainable backend design principles.