I make several calls to ObjectContext.ExecuteStoreCommand with different commands and different parameters, although I use the same parameter list (object) for several commands. I get the following exception:
System.ArgumentException: The SqlParameter is already contained by another SqlParameterCollection.
Is there a way to clear the parameters between calls, as I would do with ADO.NET?
Updated with sample code:
string sqlDeleteWebUserGreen = "delete WebUserGreen where WebUserId = @WebUserId";
string sqlDeleteWebUserBlue = "delete WebUserBlue where WebUserId = @WebUserId";
var argsDeleteWebUserXref = new DbParameter[] {
new SqlParameter { ParameterName = "WebUserId", Value = user.WebUserId }
rowsAffectedDeleteWebUserXref += base.context.ExecuteStoreCommand(sqlDeleteWebUserGreen, argsDeleteWebUserXref);
rowsAffectedDeleteWebUserXref += base.context.ExecuteStoreCommand(sqlDeleteWebUserBlue, argsDeleteWebUserXref);
UPDATE
Basically, I cannot find a better way to do this, so in the end I accepted the answer below. The only difference is that I just put the creation of the parameter in a separate method, so my calls look likebase.context.ExecuteStoreCommand(sqlDeleteWebUserBlue, MethodThatWillGiveMeTheParameterArray());
e36M3 source
share