protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree) { if (providerManifest == null) throw new ArgumentNullException("providerManifest"); if (commandTree == null) throw new ArgumentNullException("commandTree"); List<DbParameter> parameters; CommandType commandType; string commandText = SqlGenerator.GenerateSql(commandTree, out parameters, out commandType); DbCommand command = null; if (commandType == NuoDbMultipleCommands.MultipleTexts) command = new NuoDbMultipleCommands(PrepareTypeCoercions(commandTree)); else command = new NuoDbCommand(PrepareTypeCoercions(commandTree)); command.CommandText = commandText; command.CommandType = commandType; // Get the function (if any) implemented by the command tree since this influences our interpretation of parameters EdmFunction function = null; if (commandTree is DbFunctionCommandTree) { function = ((DbFunctionCommandTree)commandTree).EdmFunction; } foreach (KeyValuePair<string, TypeUsage> queryParameter in commandTree.Parameters) { NuoDbParameter parameter; // Use the corresponding function parameter TypeUsage where available (currently, the SSDL facets and // type trump user-defined facets and type in the EntityCommand). FunctionParameter functionParameter; if (null != function && function.Parameters.TryGetValue(queryParameter.Key, false, out functionParameter)) { parameter = CreateSqlParameter(functionParameter.Name, functionParameter.TypeUsage, functionParameter.Mode, DBNull.Value); } else { parameter = CreateSqlParameter(queryParameter.Key, queryParameter.Value, ParameterMode.In, DBNull.Value); } command.Parameters.Add(parameter); } // Now add parameters added as part of SQL gen (note: this feature is only safe for DML SQL gen which // does not support user parameters, where there is no risk of name collision) if (null != parameters && 0 < parameters.Count) { if (!(commandTree is DbInsertCommandTree) && !(commandTree is DbUpdateCommandTree) && !(commandTree is DbDeleteCommandTree)) { throw new InvalidOperationException("SqlGenParametersNotPermitted"); } foreach (DbParameter parameter in parameters) { command.Parameters.Add(parameter); } } return CreateCommandDefinition(command); }
protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree) { if (providerManifest == null) { throw new ArgumentNullException("providerManifest"); } if (commandTree == null) { throw new ArgumentNullException("commandTree"); } List <DbParameter> parameters; CommandType commandType; string commandText = SqlGenerator.GenerateSql(commandTree, out parameters, out commandType); DbCommand command = null; if (commandType == NuoDbMultipleCommands.MultipleTexts) { command = new NuoDbMultipleCommands(PrepareTypeCoercions(commandTree)); } else { command = new NuoDbCommand(PrepareTypeCoercions(commandTree)); } command.CommandText = commandText; command.CommandType = commandType; // Get the function (if any) implemented by the command tree since this influences our interpretation of parameters EdmFunction function = null; if (commandTree is DbFunctionCommandTree) { function = ((DbFunctionCommandTree)commandTree).EdmFunction; } foreach (KeyValuePair <string, TypeUsage> queryParameter in commandTree.Parameters) { NuoDbParameter parameter; // Use the corresponding function parameter TypeUsage where available (currently, the SSDL facets and // type trump user-defined facets and type in the EntityCommand). FunctionParameter functionParameter; if (null != function && function.Parameters.TryGetValue(queryParameter.Key, false, out functionParameter)) { parameter = CreateSqlParameter(functionParameter.Name, functionParameter.TypeUsage, functionParameter.Mode, DBNull.Value); } else { parameter = CreateSqlParameter(queryParameter.Key, queryParameter.Value, ParameterMode.In, DBNull.Value); } command.Parameters.Add(parameter); } // Now add parameters added as part of SQL gen (note: this feature is only safe for DML SQL gen which // does not support user parameters, where there is no risk of name collision) if (null != parameters && 0 < parameters.Count) { if (!(commandTree is DbInsertCommandTree) && !(commandTree is DbUpdateCommandTree) && !(commandTree is DbDeleteCommandTree)) { throw new InvalidOperationException("SqlGenParametersNotPermitted"); } foreach (DbParameter parameter in parameters) { command.Parameters.Add(parameter); } } return(CreateCommandDefinition(command)); }