Question

following question, i have a n-Tier synchronisation service that works fine when i insert new data into my sql database directly, but not if i do so in my web application.

i came to the solution that my inserts in the web application are not done through the stored procedures i defined for the desired table in my sql database.

so i tried to implement these stored procedures in the entity framework, but i get the following error:

Error 2047: A mapping function binding specifies a function straschuInventarModel.Store.sp_tblInventar_applyinsert with an unsupported parameter: sync_row_count. Output parameters may only be mapped through the RowsAffectedParameter property. Use result bindings to return values from a function invocation.

the stored procedure got implemented by updating database from model.

The error exists by the sql feature @@rowcount that can't be asigned to sync_row_count in the designer.

stored procedure for insert into tbl

ALTER procedure [dbo].[sp_tbl_applyinsert] (
@sync_last_received_anchor binary(8) , 
    @sync_client_id_hash int ,
    @sync_row_count int out,
    @idInventar varchar(5) = NULL ,
    @Aktiv bit = NULL)  

as
insert into [tbl] ([idInventar],[Aktiv]
    ,[update_originator_id]) 
    values (@idInventar, @Aktiv, @sync_client_id_hash)
set @sync_row_count = @@rowcount    

any help would be appreciative!

Was it helpful?

Solution

If you’re not interested in the actual value but rather use sync_row_count for optimistic concurrency checking, you may simply check the Rows Affected Parameter checkbox in the parameters mapping.

Apart from the case mentioned above, output parameters are not supported in EF entity model mapping functions. If you want the value be set to an entity’s property you may remove the parameter and return the value as a result instead:

ALTER procedure [dbo].[sp_tbl_applyinsert] (
    @sync_last_received_anchor binary(8), 
    @sync_client_id_hash int,
    @idInventar varchar(5) = NULL,
    @Aktiv bit = NULL)
as
    insert into [tbl] ([idInventar],[Aktiv],[update_originator_id]) 
    values (@idInventar, @Aktiv, @sync_client_id_hash)

    select @@rowcount as sync_row_count

The mapping in your entity model for sync_row_count then moves from the parameters mappings to result column bindings.

If that’s not convenient either you may still expose the stored procedure via function import as normal method of your DbContext instance. This way you are free to use any kind of parameter you like.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top