如何调用实体框架核心中的存储过程来检索数据
问题描述:
i创建了存储过程,从多个表中返回数据。
这里我无法(不知道)用参数调用存储过程。
任何人都可以帮我解决这个问题。
我试过一个场景它的回报
Hi,
i have created the stored procedure which returns data from multiple tables.
Here i i am unable(don't know) to call the stored procedure with parameter.
Can anyone please help me to resolve this.
I tried with one scenario its returns
Id = 18, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"
我尝试过:
创建了控制台应用程序。
1.为所有表格创建模型。存储过程我不能。
2. Program.cs
-------------
What I have tried:
created the console application.
1.created the models for all tables. stored procedures i cant.
2. Program.cs
-------------
var test = context.GetmessageAsync(int productId)
2. DBContext File
-----------------
2. DBContext File
-----------------
public async Task<List<Getmessage>> GetmessageAsync(int productId)
{
// Initialization.
List<Getmessage> lst = new List<Getmessage>();
try
{
// Settings.
SqlParameter usernameParam = new SqlParameter("@id", productId.ToString() ?? (object)DBNull.Value);
// Processing.
string sqlQuery = "EXEC [dbo].[Getmessage] " +
"@id";
lst = await this.Query<Getmessage>().FromSql(sqlQuery, usernameParam).ToListAsync();
}
catch (Exception ex)
{
throw ex;
}
}