本文整理汇总了C#中Record.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# Record.ContainsKey方法的具体用法?C# Record.ContainsKey怎么用?C# Record.ContainsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Record
的用法示例。
在下文中一共展示了Record.ContainsKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}
示例2: 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);
}
//.........这里部分代码省略.........
示例3: WithoutFieldTest
public void WithoutFieldTest()
{
Record record = new Record
{
{"Field1", "Value1"},
{"Field2", "Value2"},
{"Field3", "Value3"}
};
record = record.WithoutField("Field2");
Assert.IsFalse(record.ContainsKey("Field2"));
}