ADO.NET Entity Framework cannot run stored procedures.

.net ado.net entity-framework stored-procedures vb.net

Question

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]

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

Script attempting to run a stored procedure

Dim db As New MilkModel

db.Inventory_Snapshot_Create()
1
9
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). 
'http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/44a0a7c2-7c1b-43bc-98e0-4d072b94b2ab/
'==
Dim con As DbConnection = db.Connection

con.Open()

Dim cmd As DbCommand = con.CreateCommand()

With cmd
    .CommandType = CommandType.StoredProcedure
    .CommandText = "MilkModel.Inventory_Snapshot_Create"
    .ExecuteNonQuery()
    .Dispose()
End With

con.Dispose()
'==
'End dirty hack
'==
6
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:

http://msdn.microsoft.com/en-us/library/bb896231.aspx



Related Questions





Related

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