The required column 'Col0' was not present in the results of a 'FromSql' operation.
See original GitHub issueExecuting a stored procedure resulted in the following exception: System.InvalidOperationException: The required column ‘Col0’ was not present in the results of a ‘FromSql’ operation.
The stored procedure in question returns a result with no column name (dbo.sp_describe_first_result_set
shows null
for name). It seems the reverse engineering is automatically adding in “Col{index}” to the result.
I was expecting an empty partial result class.
PS: it is an easy fix for the developer to provide a column name in the stored procedure but unfortunately this database is read-only (developer lacking schema change permission).
Steps to reproduce
Create a stored procedure like so:
CREATE PROCEDURE dbo.Test()
AS
BEGIN
DECLARE @Id INT = 0
SELECT @Id
END
Reverse engineer the above-stored procedure and notice the generated result class to have a property called Col0
. When executing the stored procedure the exception is thrown.
Further technical details
EF Core version in use: 5
EF Core Power Tools version: 2.5.866
Database engine: SQL Server 2019
Visual Studio version: Visual Studio 2019 16.11.8
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
The example sproc in the 1st post does
SELECT @Id
. I read that there is no way for EF to get back this data. The only way to get the data is to alter the sproc to give it a column name (i.e.SELECT @Id AS Id
).I think that is why the
TestResult
is still generated; just that it couldn’t find any columns so the class is empty. Btw, I left out the guts of the method that you can find below.Before:
After:
Everything is fine for me.
Does Test sproc actually return anything? Can you provide a repro sproc?