SQL Server Interview Question #295

When would you use raw SQL or a stored procedure instead of LINQ?

ASP.NET Core, EF Core & SQL Server Real-World Scenarios Senior Advanced

Quick Interview Answer

LINQ is appropriate for a large portion of application data access because it is composable, type-aware, and integrated with EF Core. Raw SQL or stored procedures can be appropriate for specialized database operations, complex reporting, bulk processing, database-specific features, carefully tuned SQL, legacy database APIs, or operations that are awkward to express efficiently through LINQ. The decision should be based on maintainability, performance, security, transactional requirements, and team expertise—not on the assumption that stored procedures are always faster or that ORM queries are always sufficient.

Detailed Explanation

LINQ is appropriate for a large portion of application data access because it is composable, type-aware, and integrated with EF Core.

Raw SQL or stored procedures can be appropriate for specialized database operations, complex reporting, bulk processing, database-specific features, carefully tuned SQL, legacy database APIs, or operations that are awkward to express efficiently through LINQ.

The decision should be based on maintainability, performance, security, transactional requirements, and team expertiseβ€”not on the assumption that stored procedures are always faster or that ORM queries are always sufficient.