无法使用ADO.NET Entity Framework执行存储过程 [英] Cannot execute stored procedure with ADO.NET Entity Framework

查看:78
本文介绍了无法使用ADO.NET Entity Framework执行存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的无参数存储过程,我在下面粘贴了它。我已将存储过程导入到我的实体模型并创建了一个Function Import。永远不会创建模型中的函数,我无法使用ADO.NET实体框架执行此存储过程。我已在XML视图中打开.edmx文件,并确认此存储过程没有错误。我究竟做错了什么?是否真的不可能从实体框架中调用这样一个简单的存储过程?我已将导入函数的返回类型设置为None,看到此存储过程不需要返回任何记录集或值。

I've created a simple parameterless stored procedure which I've pasted below. I've imported the stored procedure to my Entity Model and created a Function Import. The function in the model is never created and I am unable to execute this stored procedure using the ADO.NET Entity Framework. I've opened the .edmx file in XML view and have confirmed there are no errors regarding this stored procedure. What am I doing wrong? Is it really impossible to call such a simple stored procedure from the Entity Framework? I've set the return type for the import function to None seeing this stored procedure does not need to return any recordsets or values.

存储过程:


ALTER PROC [dbo].[Inventory_Snapshot_Create]

AS

SET NOCOUNT ON

DECLARE @Inventory_Snapshot_ID int

INSERT INTO Inventory_Snapshots (snapshot_timestamp)
VALUES (GETDATE())

SET @Inventory_Snapshot_ID = SCOPE_IDENTITY()

INSERT INTO Inventory_Snapshot_Products (inventory_snapshot_id,
    idProduct, stock)

    SELECT @Inventory_Snapshot_ID, idProduct, stock
    FROM products


SET NOCOUNT OFF


代码尝试执行存储过程:

Code trying to execute stored procedure:


Dim db As New MilkModel

db.Inventory_Snapshot_Create()


推荐答案

Shawn -

Shawn-

不幸的是,C#或FunctionImports的VB代码,返回类型为"none" (或标量)不会自动生成。您必须自己添加该代码。 此论坛帖子包含有关如何信息的信息去做这个。我们正在努力在下一版的实体框架中对此进行改进。

希望有所帮助。

- 布莱恩

Unfortunately, C# or VB code for FunctionImports with return type of "none" (or scalar) is not generated automatically. You will have to add that code yourself. This forum post has information about how to do this. We are working to improve this in the next release of the Entity Framework.

Hope that helps.

-Brian


这篇关于无法使用ADO.NET Entity Framework执行存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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