English 中文(简体)
DbContext执行储存程序
原标题:Executing stored procedures from a DbContext

我在SqlServer有两个简单的储存程序:

  • SetData(@id int, @data varchar(10))
  • GetData(@id int).

<代码>GetData目前回归单行,单列结果集,但如有必要,我可以将其改为适当职能。

从<代码>DbContext上执行这些指示的最佳方式是什么?

如果可能的话,我想避免我自己进行国家关系管理和(或)揭露特定电子格式。 首先,我谨检索<代码>正文<>,并查阅<代码>。 简略*功能,但文件很坏,缺乏涉及储存程序的例子。

理想的做法是,我能够这样做:

myContext.ExecuteNonQuery("SetData", id, data);
var data = myContext.ExecuteScalar<string>("GetData", id);
最佳回答

DbContext提供这些职能。 使用:

IEumerable<...> result = myContext.Database.SqlQuery<...>(...)

为执行所储存的回收程序和程序

int result = myContext.Database.ExecuteSqlCommand(...)

a) 执行所储存的数据修改程序。

问题回答

暂无回答




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签