EF Core 6 sproc call requires sproc to include a select 0;

177 Views Asked by At

Summary:

  • .NET Core 6.0, Entity Framework Core 6.0.2.0
  • Calling a sproc via EF's command.ExecuteReader().
  • If I don't include a select 0; at the top of my sproc, no results are returned.

My C# code:

using (QuidDbContext context = GetQuidContext())
{
    context.Database.OpenConnection();
    var command = context.Database.GetDbConnection().CreateCommand();
    command.CommandText = "dbo.usp_GetBankAccounts";
    command.CommandType = CommandType.StoredProcedure;
    using (var reader = command.ExecuteReader())
    {
        if (reader.NextResult())
        {
            while (reader.Read())
            {
                int bankAccountId = Convert.ToInt32(reader.GetValue(0));
                string name = Convert.ToString(reader.GetValue(1));
            }
        }
    }
}

My sproc:

CREATE PROCEDURE dbo.usp_GetBankAccounts
AS
BEGIN
    -- MUST BE HERE:
    select 0;

    select BankAccountID, Name
        from BankAccounts
END

This code executes fine, the reader returns each BankAccount record.

However if I remove the select 0; line in the sproc, no results are returned.

0

There are 0 best solutions below