public void AddParameters(IDbCommand command, Dapper.SqlMapper.Identity identity) { var sqlCommand = (SqlCommand)command; sqlCommand.CommandType = CommandType.StoredProcedure; List <Microsoft.SqlServer.Server.SqlDataRecord> number_list = new List <Microsoft.SqlServer.Server.SqlDataRecord>(); // Create an SqlMetaData object that describes our table type. Microsoft.SqlServer.Server.SqlMetaData[] tvp_definition = { new Microsoft.SqlServer.Server.SqlMetaData("n", SqlDbType.Int) }; foreach (int n in numbers) { // Create a new record, using the metadata array above. Microsoft.SqlServer.Server.SqlDataRecord rec = new Microsoft.SqlServer.Server.SqlDataRecord(tvp_definition); rec.SetInt32(0, n); // Set the value. number_list.Add(rec); // Add it to the list. } // Add the table parameter. var p = sqlCommand.Parameters.Add("ints", SqlDbType.Structured); p.Direction = ParameterDirection.Input; p.TypeName = "int_list_type"; p.Value = number_list; }
private static bool ParametersMatch(Dapper.SqlMapper.Identity identity, DbCommand mockDbCommand) { var properties = identity.parametersType?.GetProperties() ?? new PropertyInfo[0]; return(properties.All(p => mockDbCommand.Parameters.Contains(p.Name)) && properties.Length == mockDbCommand.Parameters.Count); }
/// <summary> /// Add all the parameters needed to the command just before it executes. /// </summary> /// <param name="command">The raw command prior to execution.</param> /// <param name="identity">Information about the query.</param> public void AddParameters(IDbCommand command, Dapper.SqlMapper.Identity identity) { var sqlCommand = (SqlCommand)command; sqlCommand.CommandType = CommandType.StoredProcedure; var armIdList = new List <SqlDataRecord>(); var tvp_definition = new SqlMetaData[] { new SqlMetaData("ArmId", SqlDbType.UniqueIdentifier) }; foreach (Guid elem in _armIds) { var record = new SqlDataRecord(tvp_definition); record.SetGuid(0, elem); armIdList.Add(record); } var p = sqlCommand.Parameters.Add("@ArmIdList", SqlDbType.Structured); p.Direction = ParameterDirection.Input; p.TypeName = "ArmIdList"; p.Value = armIdList.Any() ? armIdList : null; }
void Dapper.SqlMapper.IDynamicParameters.AddParameters(IDbCommand command, Dapper.SqlMapper.Identity identity) { foreach (IDbDataParameter parameter in parameters) { command.Parameters.Add(parameter); } }
private static bool CommandTypeMatches(Dapper.SqlMapper.Identity identity, DbCommand mockDbCommand) { if (identity.commandType == 0 || identity.commandType == null) { return(true); } return(mockDbCommand.CommandType == identity.commandType.Value); }
public void AddParameters(IDbCommand command, DapperDotNet.SqlMapper.Identity identity) { foreach (var item in this.Dictionary) { var p = command.CreateParameter(); p.ParameterName = item.Key; p.Value = item.Value ?? System.DBNull.Value; command.Parameters.Add(p); } }
public bool TextMatches(DbCommand command, Dapper.SqlMapper.Identity identity) { var commandText = command.CommandText; if (commandText.Contains("@") && identity.sql.Contains("@")) { commandText = commandTextHelper.ConvertDapperParametersToUserParameters(commandText); } return(identity.sql == commandText); }
public bool Matches(DbCommand command, Dapper.SqlMapper.Identity identity) { return(TextMatches(command, identity) && ParametersMatch(identity, command) && CommandTypeMatches(identity, command)); }