Beispiel #1
0
 public SqlServerInsertBatch(SqlServerDataSourceBase dataSource, SqlServerObjectName tableName, DbDataReader dataReader, SqlServerObjectName tableTypeName, InsertOptions options) : base(dataSource)
 {
     m_Source    = dataReader;
     m_Options   = options;
     m_Table     = dataSource.DatabaseMetadata.GetTableOrView(tableName);
     m_TableType = dataSource.DatabaseMetadata.GetUserDefinedType(tableTypeName);
     if (!m_TableType.IsTableType)
     {
         throw new MappingException($"{m_TableType.Name} is not a user defined table type");
     }
 }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectDataReader{TObject}" /> class.
        /// </summary>
        /// <param name="tableType">Type of the table.</param>
        /// <param name="source">The source.</param>
        /// <param name="operationType">Type of the operation being performed.</param>
        public ObjectDataReader(UserDefinedTypeMetadata tableType, IEnumerable <TObject> source, OperationTypes operationType = OperationTypes.None)
        {
            if (tableType == null)
            {
                throw new ArgumentNullException(nameof(tableType), $"{nameof(tableType)} is null.");
            }
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source), $"{nameof(source)} is null.");
            }

            //Don't use IEnumerable<T>.Count(), as we don't want to preemptively materialize a lazy collection
            if (source is ICollection)
            {
                m_RecordCount = ((ICollection)source).Count;
            }

            m_Source = source.GetEnumerator();
            var metadata = BuildStructure(tableType.Name, tableType.Columns, true, operationType);

            m_Schema         = metadata.Schema;
            m_PropertyList   = metadata.Properties;
            m_PropertyLookup = metadata.PropertyLookup;
        }