ADO.NET Entity Framework cannot run stored procedures.

.net entity-framework stored-procedures


I made a simple stored procedure without parameters, which I've reproduced below. I've developed a Function Import and imported the stored procedure into my entity model. I am unable to run this stored procedure using the ADO.NET Entity Framework because the function in the model is never generated. I verified there are no issues with relation to this stored method by opening the.edmx file in XML view. Why am I misusing this? Is it really impossible to call such a simple stored procedure from the Entity Framework? Considering that this stored procedure does not need to return any recordsets or values, I've set the return type for the import function to None.

Stored Method:

ALTER PROC [dbo].[Inventory_Snapshot_Create]



DECLARE @Inventory_Snapshot_ID int

INSERT INTO Inventory_Snapshots (snapshot_timestamp)

SET @Inventory_Snapshot_ID = SCOPE_IDENTITY()

INSERT INTO Inventory_Snapshot_Products (inventory_snapshot_id,
    idProduct, stock)

    SELECT @Inventory_Snapshot_ID, idProduct, stock
    FROM products


Script attempting to run a stored procedure

Dim db As New MilkModel

4/26/2009 8:47:57 PM

Accepted Answer

pmarflee, many thanks.

I really came here to submit my reaction to this, but at the same moment I noticed your reply. The stored procedure I loaded into the model is actually run by this code using the connection provided by the entity framework. Entity Framework (EF) isn't where it needs to be at all, despite Microsoft's constant push for us developers to utilize it in place of LINQ to SQL and other DAL generators. Future projects won't include utilizing it until it's a more comprehensive answer.

Here is what I ultimately did:

Dim db As New MilkModel

'Begin dirty hack to execute parameterless/resultless stored
'procedure using Entity Framework (well, sort of using EF). 
Dim con As DbConnection = db.Connection


Dim cmd As DbCommand = con.CreateCommand()

With cmd
    .CommandType = CommandType.StoredProcedure
    .CommandText = "MilkModel.Inventory_Snapshot_Create"
End With

'End dirty hack
4/26/2009 9:44:46 PM

Popular Answer

The process involves adding it to the model first, then going to the entity container and Importing the function.

Details are available here:

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow