views:

30

answers:

1

I have several stored procedures in my database. For example a delete stored procedure like:

alter procedure [dbo].[DeleteFactor]
@Id uniqueidentifier
as
begin
    delete from Factors where Id = @Id
end

When I call this from code like this:

dc.ExecuteSprocAccessor("DeleteFactor", id);

then the row does not get deleted. However this code functions:

dc.ExecuteNonQuery("DeleteFactor", id);

id is a passed in parameter and of type Guid.

Can anyone explain why the second does work and the first approach does not? I find it quite strange as the first method is clearly to be used with stored procedures.

A: 

According to Retrieving Data as Objects, the ExecuteSprocAccessor method uses deferred execution (ala LINQ). So, in the first approach, since you are not accessing the results of the DeleteFactor stored procedure the SQL call is not being made.

I would use the second method anyway since you really are executing a non-query. Also, the first approach may lead to some confusion since the ExecuteSprocAccessor is designed to retrieve data. e.g. "Is data supposed to be returned here? Maybe something was missed?"

Tuzo
Thank you for the clarification. Perhaps the naming of that method should be revised to something like ExecuteSprocAccessorForRetrievingData
Nyla Pareska