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; }
AsSqlDataRecord <T>(this System.Collections.Generic.IEnumerable <T> values , string columnName) { System.Collections.Generic.List <Microsoft.SqlServer.Server.SqlDataRecord> recs = new System.Collections.Generic.List <Microsoft.SqlServer.Server.SqlDataRecord>(); bool isFirst = true; Microsoft.SqlServer.Server.SqlMetaData metadata = null; foreach (T thisValue in values) { if (isFirst) { metadata = Microsoft.SqlServer.Server.SqlMetaData.InferFromValue(thisValue, columnName); } Microsoft.SqlServer.Server.SqlDataRecord r = new Microsoft.SqlServer.Server.SqlDataRecord(metadata); r.SetValues(thisValue); recs.Add(r); isFirst = false; } // Next thisValue // Annoying, but SqlClient wants null instead of 0 rows if (recs.Count == 0) { recs = null; } return(recs); } // End Function AsSqlDataRecord
public void AddParameters(IDbCommand command, SqlMapper.Identity identity) { var sqlCommand = (SqlCommand)command; sqlCommand.CommandType = CommandType.StoredProcedure; var accountList = new List <Microsoft.SqlServer.Server.SqlDataRecord>(); Microsoft.SqlServer.Server.SqlMetaData[] tvpDefinition = { new Microsoft.SqlServer.Server.SqlMetaData("AccountId", SqlDbType.BigInt) }; foreach (var accountId in _accountIds) { Microsoft.SqlServer.Server.SqlDataRecord rec = new Microsoft.SqlServer.Server.SqlDataRecord(tvpDefinition); rec.SetInt64(0, accountId); accountList.Add(rec); } var p = sqlCommand.Parameters.Add("@accountIds", SqlDbType.Structured); p.Direction = ParameterDirection.Input; p.TypeName = "[employer_financial].[AccountIds]"; p.Value = accountList; sqlCommand.Parameters.AddRange(_additionalParameters.ToArray()); }
public void AddParameter(IDbCommand command, string name) { var sqlCommand = (SqlCommand)command; sqlCommand.CommandType = CommandType.StoredProcedure; var ids = new List <Microsoft.SqlServer.Server.SqlDataRecord>(); // Create an SqlMetaData object that describes our table type. Microsoft.SqlServer.Server.SqlMetaData[] tvpDefinition = { new Microsoft.SqlServer.Server.SqlMetaData("Id", SqlDbType.Int) }; foreach (var id in Ids) { // Create a new record, using the metadata array above. var rec = new Microsoft.SqlServer.Server.SqlDataRecord(tvpDefinition); rec.SetInt32(0, id); // Set the value. ids.Add(rec); // Add it to the list. } // Add the table parameter. var p = sqlCommand.Parameters.Add(name, SqlDbType.Structured); p.Direction = ParameterDirection.Input; p.TypeName = "Ids"; p.Value = ids; }
public void AddParameters(IDbCommand command, SqlMapper.Identity identity) { var sqlCommand = (SqlCommand)command; sqlCommand.CommandType = CommandType.StoredProcedure; var list = new List <Microsoft.SqlServer.Server.SqlDataRecord>(); // Create an SqlMetaData object that describes our table type. Microsoft.SqlServer.Server.SqlMetaData[] tvpDefinition = { new Microsoft.SqlServer.Server.SqlMetaData("n", SqlDbType.VarChar, 200) }; foreach (var value in this.values) { // Create a new record, using the metadata array above. var rec = new Microsoft.SqlServer.Server.SqlDataRecord(tvpDefinition); rec.SetString(0, value); // Set the value. list.Add(rec); // Add it to the list. } // Add the table parameter. var p = sqlCommand.Parameters.Add(parameterName, SqlDbType.Structured); p.Direction = ParameterDirection.Input; p.TypeName = "[LAF].[VarcharListTableType]"; p.Value = list; foreach (var additionalParameter in additionalParameters) { sqlCommand.Parameters.Add(additionalParameter); } }
public void AddParameters(IDbCommand command, SqlMapper.Identity identity) { var sqlCommand = (SqlCommand)command; sqlCommand.CommandType = CommandType.StoredProcedure; var eventTypesList = new List <Microsoft.SqlServer.Server.SqlDataRecord>(); Microsoft.SqlServer.Server.SqlMetaData[] tvpDefinition = { new Microsoft.SqlServer.Server.SqlMetaData("Name", SqlDbType.VarChar, 255) }; foreach (var eventType in _eventTypes) { Microsoft.SqlServer.Server.SqlDataRecord rec = new Microsoft.SqlServer.Server.SqlDataRecord(tvpDefinition); rec.SetString(0, eventType); eventTypesList.Add(rec); } var p = sqlCommand.Parameters.Add("@eventTypes", SqlDbType.Structured); p.Direction = ParameterDirection.Input; p.TypeName = "[dbo].[eventType]"; p.Value = eventTypesList; sqlCommand.Parameters.AddRange(_parameters.ToArray()); }
public void CustomEmployeesMapSqlRecord(Employee mapObject, Microsoft.SqlServer.Server.SqlDataRecord record, int rowIndex, IEnumerable <string> errors) { record.SetValue(record.GetOrdinal("SSN"), mapObject.L2SSN); record.SetValue(record.GetOrdinal("Name"), mapObject.L1Name); string errXml = errors.Count() > 0 ? FileIOHelpers.ErrorsToXml(errors, rowIndex) : null; record.SetValue(record.GetOrdinal("Errors"), errXml); }
public void MapSqlRecord(Microsoft.SqlServer.Server.SqlDataRecord record, int rowIndex, IEnumerable <string> errors) { record.SetString("SSN", this.L2SSN); record.SetString("Name", this.L1Name); string errs = errors.Count() > 0 ? FileIOHelpers.ErrorsToXml(errors, rowIndex) : null; record.SetString("Errors", errs); }
public new void AddParameters(IDbCommand command, Dapper.SqlMapper.Identity identity) { base.AddParameters(command, 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; }