Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework: Map output parameters from stored procedure?

I want to map stored procedure OUTPUT parameters to an entity.

e.g.,

PROCEDURE ForExample
@ID int,
@LastUpdate datetime OUTPUT
AS
Update EntityTable Set LastUpdate = GETDATE() Where ID = @ID
Select @LastUpdate = LastUpdate From EntityTable Where ID = @ID

I want to map the @LastUpdate output parameter to an entity property.

In the Stored Procedure Mapping dialog, the @LastUpdate parameter shows up as an InOut parameter (green arrows going both ways). Whether I map the parameter to a property or not, I get the same error:

A mapping function binding specifies a function Model.Store.ForExample with an unsupported parameter: LastUpdate. Output parameters may only be mapped through the RowsAffectedParameter property. Use result bindings to return values from a function invocation.

I tried adding a manual binding for LastUpdate in the "Result Column Bindings" but that didn't work.

Is what I'm trying to do supported by EF 4 and if so how is it done?

like image 671
with Avatar asked Feb 23 '26 23:02

with


1 Answers

As it's said in the error text, "Output parameters may only be mapped through the RowsAffectedParameter property. Use result bindings to return values from a function invocation"

If you want your procedure to return some value, e.g. last update, it should return it via a result set. That means, your stored procedure should look like this:

PROCEDURE ForExample
@ID int,
AS
Update EntityTable Set LastUpdate = GETDATE() Where ID = @ID
/*return lastupdate in resultset*/
Select LastUpdate as LastUpdate From EntityTable Where ID = @ID

And than you should map your result set column to lastupdate property like this: enter image description here

And stored procedure's output parameters can only be used for optimistic concurrency.

like image 114
Anatoly U Avatar answered Feb 25 '26 11:02

Anatoly U



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!