0

I am getting below error when I am calling procedure from entity framework with parameter

alter proc GetResultsForCampaign @aa int as begin SELECT aa from xyz end

calling code var result = context.Database.SqlQuery("GetResultsForCampaign @aa", 22).ToList();

error must declare the variable @aa

Progman
  • 16,827
  • 6
  • 33
  • 48
amit
  • 1
  • 1
  • 1
    Does this answer your question? [How to call Stored Procedure in Entity Framework 6 (Code-First)?](https://stackoverflow.com/questions/20901419/how-to-call-stored-procedure-in-entity-framework-6-code-first) – Progman Nov 25 '21 at 21:56

1 Answers1

0

You can try this.

using Microsoft.Data.SqlClient;

var result = await db.Context
  .FromSqlRaw("exec [dbo].[your_sp] @param1, @param2", 
    new SqlParameter("param1", value1),     
    new SqlParameter("param2", value2))
  .AsNoTracking() // optional
  .ToListAsync()
Pato
  • 462
  • 2
  • 4
  • 11