本文整理汇总了C#中Record.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Record.Add方法的具体用法?C# Record.Add怎么用?C# Record.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Record
的用法示例。
在下文中一共展示了Record.Add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteRecord
public RecordCollection ExecuteRecord(string SQLText)
{
RecordCollection rcc = new RecordCollection();
using (IDataReader rd = ExecuteReader(SQLText))
{
while (rd.Read())
{
Record rc = new Record();
for (int i = 0; i < rd.FieldCount; i++)
{
rc.Add(rd.GetName(i), rd.GetValue(i));
}
rcc.Add(rc);
}
}
return rcc;
}
示例2: GetOutputAsRecord
/// <summary>
/// An extension method to extract outputs from a record dictionary.
/// </summary>
/// <param name="dbParameters"> The target enumerable of data paramters. </param>
/// <returns> A dictionary with record key/value pairs of OUTPUT data. </returns>
public static IRecord GetOutputAsRecord(this IEnumerable<DbParameter> dbParameters)
{
IRecord output;
if ((object)dbParameters == null)
throw new ArgumentNullException(nameof(dbParameters));
output = new Record();
foreach (DbParameter dbParameter in dbParameters)
{
if (dbParameter.Direction != ParameterDirection.InputOutput &&
dbParameter.Direction != ParameterDirection.Output &&
dbParameter.Direction != ParameterDirection.ReturnValue)
continue;
output.Add(dbParameter.ParameterName, dbParameter.Value);
}
return output;
}
示例3: ExecuteRecords
public IEnumerable<IDictionary<string, object>> ExecuteRecords(bool schemaOnly, Type connectionType, string connectionString, bool transactional, IsolationLevel isolationLevel, CommandType commandType, string commandText, IEnumerable<DbParameter> commandParameters, Action<int> resultsetCallback = null)
{
DbTransaction dbTransaction;
const bool OPEN = true;
IList<IRecord> records;
// force no preparation
const bool COMMAND_PREPARE = false;
// force provider default timeout
object COMMAND_TIMEOUT = null; /*int?*/
CommandBehavior commandBehavior;
int resultsetIndex = 0;
ReadOnlyCollection<DbColumn> dbColumns;
DbColumn dbColumn;
PropertyInfo[] propertyInfos;
PropertyInfo propertyInfo;
if ((object)connectionType == null)
throw new ArgumentNullException(nameof(connectionType));
if ((object)connectionString == null)
throw new ArgumentNullException(nameof(connectionString));
using (DbConnection dbConnection = (DbConnection)Activator.CreateInstance(connectionType))
{
if (OPEN)
{
dbConnection.ConnectionString = connectionString;
dbConnection.Open();
if (transactional)
dbTransaction = dbConnection.BeginTransaction(isolationLevel);
else
dbTransaction = null;
}
using (DbCommand dbCommand = dbConnection.CreateCommand())
{
dbCommand.Transaction = dbTransaction;
dbCommand.CommandType = commandType;
dbCommand.CommandText = commandText;
if ((object)COMMAND_TIMEOUT != null)
dbCommand.CommandTimeout = (int)COMMAND_TIMEOUT;
// add parameters
if ((object)commandParameters != null)
{
foreach (DbParameter commandParameter in commandParameters)
{
if ((object)commandParameter.Value == null)
commandParameter.Value = DBNull.Value;
dbCommand.Parameters.Add(commandParameter);
}
}
if (COMMAND_PREPARE)
dbCommand.Prepare();
records = new List<IRecord>();
commandBehavior = schemaOnly ? CommandBehavior.SchemaOnly : CommandBehavior.Default;
// wrap reader with proxy
using (DbDataReader dbDataReader = new WrappedDbDataReader.__(dbCommand.ExecuteReader(commandBehavior)))
{
Record record;
string key;
object value;
if (!schemaOnly)
{
do
{
if ((object)resultsetCallback != null)
resultsetCallback(resultsetIndex++);
while (dbDataReader.Read())
{
record = new Record();
for (int columnIndex = 0; columnIndex < dbDataReader.FieldCount; columnIndex++)
{
key = dbDataReader.GetName(columnIndex);
value = dbDataReader.GetValue(columnIndex);
value = this.DataTypeFascade.ChangeType<object>(value);
if (record.ContainsKey(key) || (key ?? string.Empty).Length == 0)
key = string.Format("Column_{0:0000}", columnIndex);
record.Add(key, value);
}
records.Add(record);
}
//.........这里部分代码省略.........
示例4: GetRecordsFromReader
/// <summary>
/// Execute a command against a data source, mapping the data reader to an enumerable of record dictionaries.
/// This method perfoms LAZY LOADING/DEFERRED EXECUTION.
/// Note that THE DATA READER WILL NOT BE DISPOSED UPON ENUMERATION OR FOREACH BRANCH OUT.
/// </summary>
/// <param name="dbDataReader"> The target data reader. </param>
/// <param name="recordsAffectedCallback"> Executed when the output count of records affected is available to return (post enumeration). </param>
/// <returns> An enumerable of record dictionary instances, containing key/value pairs of data. </returns>
public IEnumerable<IRecord> GetRecordsFromReader(DbDataReader dbDataReader, Action<int> recordsAffectedCallback)
{
IRecord record;
int recordsAffected;
int recordIndex = 0;
string key;
object value;
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetRecordsFromReader(...): enter", typeof(AdoNetStreamingFascade).Name));
if ((object)dbDataReader == null)
throw new ArgumentNullException(nameof(dbDataReader));
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetRecordsFromReader(...): before yield", typeof(AdoNetStreamingFascade).Name));
while (dbDataReader.Read())
{
record = new Record();
for (int columnIndex = 0; columnIndex < dbDataReader.FieldCount; columnIndex++)
{
key = dbDataReader.GetName(columnIndex);
value = dbDataReader.GetValue(columnIndex).ChangeType<object>();
if (record.ContainsKey(key) || (key ?? string.Empty).Length == 0)
key = string.Format("Column_{0:0000}", columnIndex);
record.Add(key, value);
}
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetRecordsFromReader(...): on yield", typeof(AdoNetStreamingFascade).Name));
yield return record; // LAZY PROCESSING INTENT HERE / DO NOT FORCE EAGER LOAD
}
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetRecordsFromReader(...): after yield", typeof(AdoNetStreamingFascade).Name));
recordsAffected = dbDataReader.RecordsAffected;
if ((object)recordsAffectedCallback != null)
recordsAffectedCallback(recordsAffected);
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetRecordsFromReader(...): leave", typeof(AdoNetStreamingFascade).Name));
}
示例5: ParseDict
/// <summary>
/// Parses a dictinary <content> element and returns a record
/// object containing the parsed values.
/// </summary>
/// <param name="element">An XML element.</param>
/// <returns>The record.</returns>
internal Record ParseDict(XmlElement element)
{
Trace.Assert(element.Name.Equals("s:dict"));
if (element.FirstChild == null)
{
return null;
}
List<XmlElement> children = GetChildElements(element);
int count = children.Count;
if (count == 0)
{
return null;
}
Record result = new Record();
foreach (XmlElement child in children)
{
Trace.Assert(child.Name.Equals("s:key"));
string key = child.GetAttribute("name");
object value = this.ParseValue(child);
if (value != null)
{
result.Add(key, value);
}
}
return result;
}
示例6: GetSchemaRecordsFromReader
/// <summary>
/// Execute a command against a data source, mapping the data reader GetSchemaTable() result to an enumerable of record dictionaries.
/// This method perfoms LAZY LOADING/DEFERRED EXECUTION.
/// Note that THE DATA READER WILL NOT BE DISPOSED UPON ENUMERATION OR FOREACH BRANCH OUT.
/// </summary>
/// <param name="dataReader"> The target data reader. </param>
/// <param name="recordsAffectedCallback"> Executed when the output count of records affected is available to return (post enumeration). </param>
/// <returns> An enumerable of record dictionary instances, containing key/value pairs of schema metadata. </returns>
public IEnumerable<IRecord> GetSchemaRecordsFromReader(IDataReader dataReader, Action<int> recordsAffectedCallback)
{
IRecord record;
int recordsAffected;
string key;
object value;
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetSchemaRecordsFromReader(...): enter", typeof(AdoNetYieldingFascade).Name));
if ((object)dataReader == null)
throw new ArgumentNullException("dataReader");
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetSchemaRecordsFromReader(...): before yield", typeof(AdoNetYieldingFascade).Name));
using (DataTable dataTable = dataReader.GetSchemaTable())
{
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetSchemaRecordsFromReader(...): use table", typeof(AdoNetYieldingFascade).Name));
if ((object)dataTable != null)
{
foreach (DataRow dataRow in dataTable.Rows)
{
record = new Record();
for (int index = 0; index < dataTable.Columns.Count; index++)
{
key = dataTable.Columns[index].ColumnName;
value = dataRow[index].ChangeType<object>();
record.Add(key, value);
}
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetSchemaRecordsFromReader(...): on yield", typeof(AdoNetYieldingFascade).Name));
yield return record; // LAZY PROCESSING INTENT HERE / DO NOT FORCE EAGER LOAD
}
}
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetSchemaRecordsFromReader(...): dispose table", typeof(AdoNetYieldingFascade).Name));
}
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetSchemaRecordsFromReader(...): after yield", typeof(AdoNetYieldingFascade).Name));
recordsAffected = dataReader.RecordsAffected;
if ((object)recordsAffectedCallback != null)
recordsAffectedCallback(recordsAffected);
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetSchemaRecordsFromReader(...): leave", typeof(AdoNetYieldingFascade).Name));
}
示例7: GetSchemaRecordsFromReader
/// <summary>
/// Execute a command against a data source, mapping the data reader GetSchemaTable() result to an enumerable of record dictionaries.
/// This method perfoms LAZY LOADING/DEFERRED EXECUTION.
/// Note that THE DATA READER WILL NOT BE DISPOSED UPON ENUMERATION OR FOREACH BRANCH OUT.
/// </summary>
/// <param name="dbDataReader"> The target data reader. </param>
/// <param name="recordsAffectedCallback"> Executed when the output count of records affected is available to return (post enumeration). </param>
/// <returns> An enumerable of record dictionary instances, containing key/value pairs of schema metadata. </returns>
public IEnumerable<IRecord> GetSchemaRecordsFromReader(DbDataReader dbDataReader, Action<int> recordsAffectedCallback)
{
ReadOnlyCollection<DbColumn> dbColumns;
DbColumn dbColumn;
PropertyInfo[] propertyInfos;
PropertyInfo propertyInfo;
Record record;
int recordsAffected;
string key;
object value;
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetSchemaRecordsFromReader(...): enter", typeof(AdoNetStreamingFascade).Name));
if ((object)dbDataReader == null)
throw new ArgumentNullException(nameof(dbDataReader));
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetSchemaRecordsFromReader(...): before yield", typeof(AdoNetStreamingFascade).Name));
if (!dbDataReader.CanGetColumnSchema())
throw new NotSupportedException(string.Format("The connection command type '{0}' does not support schema access.", dbDataReader.GetType().FullName));
dbColumns = dbDataReader.GetColumnSchema();
{
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetSchemaRecordsFromReader(...): use table", typeof(AdoNetStreamingFascade).Name));
if ((object)dbColumns != null)
{
for (int index = 0; index < dbColumns.Count; index++)
{
dbColumn = dbColumns[index];
propertyInfos = dbColumn.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty);
record = new Record();
record.Context = dbColumn;
if ((object)propertyInfos != null)
{
for (int i = 0; i < propertyInfos.Length; i++)
{
propertyInfo = propertyInfos[i];
if (propertyInfo.GetIndexParameters().Any())
continue;
key = propertyInfo.Name;
value = propertyInfo.GetValue(dbColumn);
value = value.ChangeType<object>();
record.Add(key, value);
}
}
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetSchemaRecordsFromReader(...): on yield", typeof(AdoNetStreamingFascade).Name));
yield return record; // LAZY PROCESSING INTENT HERE / DO NOT FORCE EAGER LOAD
}
}
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetSchemaRecordsFromReader(...): dispose table", typeof(AdoNetStreamingFascade).Name));
}
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetSchemaRecordsFromReader(...): after yield", typeof(AdoNetStreamingFascade).Name));
recordsAffected = dbDataReader.RecordsAffected;
if ((object)recordsAffectedCallback != null)
recordsAffectedCallback(recordsAffected);
OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetSchemaRecordsFromReader(...): leave", typeof(AdoNetStreamingFascade).Name));
}