0

I am using VS 2019 and I have a simple Web API method to execute a stored procedure that returns one string. I am using Entity Framework Core version 3.1.31.

When I am trying to call the stored procedure in my Web API method by using

context.Database.FromSqlRawAsync

I get an error

DatabaseFacade does not contain a definition for FromSqlRaw...

However if I use ExecuteSqlRaw, it accepts it and does not throw any error.

Any suggestion on how to resolve this?

I have tried installing Microsoft.EntityFrameworkCore.Relational package version 3.1.31 from nuget package manager. I am also using using Microsoft.EntityFrameworkCore statement in the Web API controller.

What else do I need to do?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
MaryBhatta
  • 15
  • 5
  • 1
    `FromSql{Raw|Interpolated}` are for executing *queries*, and are defined for `DbSet`s, not `DbContext.Database`. For SPs returning single values `ExecuteSqlRaw ` is indeed the right method to be used ("by design"). – Ivan Stoev Jan 30 '23 at 06:54

0 Answers0