public virtual IRelationalValueBufferFactory CreateValueBufferFactory(
            IRelationalValueBufferFactoryFactory relationalValueBufferFactoryFactory, DbDataReader _)
        {
            Check.NotNull(relationalValueBufferFactoryFactory, nameof(relationalValueBufferFactoryFactory));

            return(relationalValueBufferFactoryFactory
                   .CreateValueBufferFactory(_selectExpression.GetProjectionTypes().ToArray(), indexMap: null));
        }
示例#2
0
 private IRelationalValueBufferFactory CreateValueBufferFactory()
 => _valueBufferFactoryFactory
 .CreateValueBufferFactory(
     ColumnModifications
     .Where(c => c.IsRead)
     .Select(c => c.Property.ClrType)
     .ToArray(),
     indexMap: null);
示例#3
0
        public virtual IRelationalValueBufferFactory CreateValueBufferFactory(
            IRelationalValueBufferFactoryFactory relationalValueBufferFactoryFactory, DbDataReader dataReader)
        {
            Check.NotNull(relationalValueBufferFactoryFactory, nameof(relationalValueBufferFactoryFactory));
            Check.NotNull(dataReader, nameof(dataReader));

            var readerColumns
                = Enumerable
                  .Range(0, dataReader.FieldCount)
                  .Select(i => new
            {
                Name    = dataReader.GetName(i),
                Ordinal = i
            })
                  .ToList();

            var types    = new Type[_selectExpression.Projection.Count];
            var indexMap = new int[_selectExpression.Projection.Count];

            for (var i = 0; i < _selectExpression.Projection.Count; i++)
            {
                var aliasExpression = _selectExpression.Projection[i] as AliasExpression;

                if (aliasExpression != null)
                {
                    var columnName
                        = aliasExpression.Alias
                          ?? aliasExpression.TryGetColumnExpression()?.Name;

                    if (columnName != null)
                    {
                        var readerColumn
                            = readerColumns.SingleOrDefault(c =>
                                                            string.Equals(columnName, c.Name, StringComparison.OrdinalIgnoreCase));

                        if (readerColumn == null)
                        {
                            throw new InvalidOperationException(Strings.FromSqlMissingColumn(columnName));
                        }

                        types[i]    = _selectExpression.Projection[i].Type;
                        indexMap[i] = readerColumn.Ordinal;
                    }
                }
            }

            return(relationalValueBufferFactoryFactory.CreateValueBufferFactory(types, indexMap));
        }