private DbCommand PrepareEntityCommandBeforeExecution(EntityCommand entityCommand) { if (1 != this._mappedCommandDefinitions.Count) { throw new NotSupportedException("MARS"); } EntityTransaction entityTransaction = entityCommand.ValidateAndGetEntityTransaction(); InterceptableDbCommand interceptableDbCommand = new InterceptableDbCommand(this._mappedCommandDefinitions[0].CreateCommand(), entityCommand.InterceptionContext, (DbDispatchers)null); CommandHelper.SetStoreProviderCommandState(entityCommand, entityTransaction, (DbCommand)interceptableDbCommand); bool flag = false; if (interceptableDbCommand.Parameters != null) { foreach (DbParameter parameter in interceptableDbCommand.Parameters) { int index = entityCommand.Parameters.IndexOf(parameter.ParameterName); if (-1 != index) { EntityCommandDefinition.SyncParameterProperties(entityCommand.Parameters[index], parameter, this._storeProviderServices); if (parameter.Direction != ParameterDirection.Input) { flag = true; } } } } if (flag) { entityCommand.SetStoreProviderCommand((DbCommand)interceptableDbCommand); } return((DbCommand)interceptableDbCommand); }
private DbCommand PrepareEntityCommandBeforeExecution(EntityCommand entityCommand) { if (1 != _mappedCommandDefinitions.Count) { throw new NotSupportedException("MARS"); } var entityTransaction = entityCommand.ValidateAndGetEntityTransaction(); var definition = _mappedCommandDefinitions[0]; var storeProviderCommand = new InterceptableDbCommand(definition.CreateCommand(), entityCommand.InterceptionContext); CommandHelper.SetStoreProviderCommandState(entityCommand, entityTransaction, storeProviderCommand); // Copy over the values from the map command to the store command; we // assume that they were not renamed by either the plan compiler or SQL // Generation. // // Note that this pretty much presumes that named parameters are supported // by the store provider, but it might work if we don't reorder/reuse // parameters. // // Note also that the store provider may choose to add parameters to thier // command object for some things; we'll only copy over the values for // parameters that we find in the EntityCommands parameters collection, so // we won't damage anything the store provider did. var hasOutputParameters = false; // Could be null for some providers, don't remove this check if (storeProviderCommand.Parameters != null) { foreach (DbParameter storeParameter in storeProviderCommand.Parameters) { // I could just use the string indexer, but then if I didn't find it the // consumer would get some ParameterNotFound exeception message and that // wouldn't be very meaningful. Instead, I use the IndexOf method and // if I don't find it, it's not a big deal (The store provider must // have added it). var parameterOrdinal = entityCommand.Parameters.IndexOf(storeParameter.ParameterName); if (-1 != parameterOrdinal) { var entityParameter = entityCommand.Parameters[parameterOrdinal]; // _storeProviderServices will be null if this object was created via // the test constructor - but if so we shouldn't be calling this DebugCheck.NotNull(_storeProviderServices); SyncParameterProperties(entityParameter, storeParameter, _storeProviderServices); if (storeParameter.Direction != ParameterDirection.Input) { hasOutputParameters = true; } } } } // If the EntityCommand has output parameters, we must synchronize parameter values when // the reader is closed. Tell the EntityCommand about the store command so that it knows // where to pull those values from. if (hasOutputParameters) { entityCommand.SetStoreProviderCommand(storeProviderCommand); } return(storeProviderCommand); }
private DbCommand PrepareEntityCommandBeforeExecution(EntityCommand entityCommand) { if (1 != _mappedCommandDefinitions.Count) { throw new NotSupportedException("MARS"); } var entityTransaction = entityCommand.ValidateAndGetEntityTransaction(); var definition = _mappedCommandDefinitions[0]; var storeProviderCommand = new InterceptableDbCommand(definition.CreateCommand(), entityCommand.InterceptionContext); CommandHelper.SetStoreProviderCommandState(entityCommand, entityTransaction, storeProviderCommand); // Copy over the values from the map command to the store command; we // assume that they were not renamed by either the plan compiler or SQL // Generation. // // Note that this pretty much presumes that named parameters are supported // by the store provider, but it might work if we don't reorder/reuse // parameters. // // Note also that the store provider may choose to add parameters to thier // command object for some things; we'll only copy over the values for // parameters that we find in the EntityCommands parameters collection, so // we won't damage anything the store provider did. var hasOutputParameters = false; // Could be null for some providers, don't remove this check if (storeProviderCommand.Parameters != null) { foreach (DbParameter storeParameter in storeProviderCommand.Parameters) { // I could just use the string indexer, but then if I didn't find it the // consumer would get some ParameterNotFound exeception message and that // wouldn't be very meaningful. Instead, I use the IndexOf method and // if I don't find it, it's not a big deal (The store provider must // have added it). var parameterOrdinal = entityCommand.Parameters.IndexOf(storeParameter.ParameterName); if (-1 != parameterOrdinal) { var entityParameter = entityCommand.Parameters[parameterOrdinal]; // _storeProviderServices will be null if this object was created via // the test constructor - but if so we shouldn't be calling this DebugCheck.NotNull(_storeProviderServices); SyncParameterProperties(entityParameter, storeParameter, _storeProviderServices); if (storeParameter.Direction != ParameterDirection.Input) { hasOutputParameters = true; } } } } // If the EntityCommand has output parameters, we must synchronize parameter values when // the reader is closed. Tell the EntityCommand about the store command so that it knows // where to pull those values from. if (hasOutputParameters) { entityCommand.SetStoreProviderCommand(storeProviderCommand); } return storeProviderCommand; }