本文整理汇总了C#中System.Data.Common.DbDataReader.CanGetColumnSchema方法的典型用法代码示例。如果您正苦于以下问题:C# DbDataReader.CanGetColumnSchema方法的具体用法?C# DbDataReader.CanGetColumnSchema怎么用?C# DbDataReader.CanGetColumnSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Common.DbDataReader
的用法示例。
在下文中一共展示了DbDataReader.CanGetColumnSchema方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}