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?
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:

And stored procedure's output parameters can only be used for optimistic concurrency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With