A practical guide to managing stored procedures in .NET Code First projects using Entity Framework Core. Covers creating stored procedures inside blank EF Core migrations with `migrationBuilder.Sql()`, ensuring they are version-controlled and applied automatically. Also explains when to use `FromSqlRaw` (no parameters), `FromSqlInterpolated` (parameterized queries returning entities), and `ExecuteSqlInterpolatedAsync` (INSERT/UPDATE/DELETE commands), with full code examples using Minimal API endpoints.

7m read timeFrom medium.com
Post cover image
Table of contents
IntroductionThe Starting PointWhat Are Stored Procedures and When to Use ThemGet Remigiusz Zalewski’s stories in your inboxCreating Stored Procedures in EF Core MigrationsCreating a Blank MigrationWriting the MigrationA Procedure with Parameters⚡ Calling Stored Procedures from Minimal API EndpointsFromSqlRaw - No ParametersFromSqlInterpolated - Parameterized QueriesExecuteSqlInterpolatedAsync - Commands (No Return Value)The Full BooksStoredProcedureModuleMigrations Keep Everything in SyncKey Takeaways

Sort: