79277252

Date: 2024-12-13 04:49:27
Score: 1
Natty:
Report link

The question appears on top of my search result when I try to solve a similar issue.

This is what I have found:

If your stored procedure is meant to return a model, you need to make sure the field names in your stored procedure can be exactly mapped to the model in your C# code (cases, no white space, underscore etc). If you end up using the ComplexTypeMapping feature provided by EntityFramework, the EF will attempt to create temporary stored procedure in your database and execute it with a fresh plan.

In my particular situation, I have a field name with white space [Student Name] in my stored procedure, the EF automatically created a model with field Student_Name in C#, which triggered the EF to create a temporary stored proc when exec my stored proc. And the code took minutes to run. After removing the white space from my stored proc and refreshing EF schema, the same code can finish in seconds.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: E H