Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Closed Issue: Code first sproc mapping: revisit RowsAffected parameter creation [1235]

$
0
0
(Note for triage: we discussed this with Andrew and we agreed we should try to fix it for EF6 as the current behavior is not consistent nor the most helpful but changing it later would be a breaking change. Andrew believes that the fix should be easy)

Currently by convention we include the RowsAffected parameter in stored procedures (i.e. we include it in the signature of the stored procedure and we add "SET @RowsAffected = @@ROWCOUNT" at the end of the body) when there is a declared concurrency token in the entity. If you try to specify explicitly a different name for the parameter for a stored procedure for which we haven't added it you get the following exception:

```
System.InvalidOperationException: A rows affected parameter was not found on the modification function 'Item_Delete'. Ensure that the target entity has at least one concurrency token.
```

In reality the runtime does not need a RowsAffected output parameter to be able to control concurrency as it can get the rows affected from the command execution directly. The inclusion of a RowsAffected parameter should be an option to those defining the stored procedures. The option is very useful in cases in which the logic in the stored procedure differs from normal CUD operations in which the number of rows affected can be normally retrieved by ADO.NET (e.g. for a stored procedure that has to "fake" inserts or deletes).

__Open issue__: in the current API the only way available to indicate that a RowsAffected parameter is desired is to specify its name, e.g.:

```
modelBuilder.Entity<Item>()
.MapToStoredProcedures(
c => c.Delete(
dc => dc.RowsAffectedParameter("rowsAffected")));
```

We should consider adding a way to specify that the parameter is desired but without having to specify a name.
Comments: Verified, closing

Viewing all articles
Browse latest Browse all 10318

Trending Articles