如何调用实体框架核心中的存储过程来检索数据 [英] How do I call the stored procedure in entity framework core to retrieve the data

查看:132
本文介绍了如何调用实体框架核心中的存储过程来检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





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;
	}
}

推荐答案

如何:使用EntityCommand执行参数化存储过程Microsoft Docs [ ^ ]



实体框架的EntityClient提供程序Microsoft Docs [ ^ ]


这篇关于如何调用实体框架核心中的存储过程来检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆