예제 #1
0
        /// <summary>
        /// Joins the header with the specified one.
        /// </summary>
        /// <param name="joined">The header to join.</param>
        /// <returns>The joined header.</returns>
        public RecordSetHeader Join(RecordSetHeader joined)
        {
            var columnCount = Columns.Count;
            var newColumns  = new List <Column>(Columns);

            newColumns.AddRange(
                from c in joined.Columns
                select c.Clone(columnCount + c.Index));

            var newFieldTypes = new Type[newColumns.Count];

            for (var i = 0; i < newColumns.Count; i++)
            {
                newFieldTypes[i] = newColumns[i].Type;
            }
            var newTupleDescriptor = TupleDescriptor.Create(newFieldTypes);

            var groups = new List <ColumnGroup>(ColumnGroups);

            groups.AddRange(
                joined.ColumnGroups
                .Select(g => new ColumnGroup(
                            g.TypeInfoRef,
                            g.Keys.Select(i => columnCount + i),
                            g.Columns.Select(i => columnCount + i))));

            return(new RecordSetHeader(
                       newTupleDescriptor,
                       newColumns,
                       groups,
                       OrderTupleDescriptor,
                       Order));
        }
예제 #2
0
        /// <summary>
        /// Joins the header with the specified one.
        /// </summary>
        /// <param name="joined">The header to join.</param>
        /// <returns>The joined header.</returns>
        public RecordSetHeader Join(RecordSetHeader joined)
        {
            var columns = new List <Column>(Columns);
            var originalColumnsCount = Columns.Count;

            columns.AddRange(
                from c in joined.Columns
                select c.Clone(originalColumnsCount + c.Index));

            var types = new List <Type>(TupleDescriptor);

            types.AddRange(joined.TupleDescriptor);

            var groups = new List <ColumnGroup>(ColumnGroups);

            groups.AddRange(
                joined.ColumnGroups
                .Select(g => new ColumnGroup(
                            g.TypeInfoRef,
                            g.Keys.Select(i => originalColumnsCount + i),
                            g.Columns.Select(i => originalColumnsCount + i))));

            return(new RecordSetHeader(
                       TupleDescriptor.Create(types),
                       columns,
                       groups,
                       OrderTupleDescriptor,
                       Order));
        }
        /// <summary>
        /// Joins the header with the specified one.
        /// </summary>
        /// <param name="joined">The header to join.</param>
        /// <returns>The joined header.</returns>
        public RecordSetHeader Join(RecordSetHeader joined)
        {
            var columnCount = Columns.Count;
            var newColumns  = new List <Column>(columnCount + joined.Columns.Count);

            newColumns.AddRange(Columns);
            foreach (var c in joined.Columns)
            {
                newColumns.Add(c.Clone(columnCount + c.Index));
            }

            var newFieldTypes = new Type[newColumns.Count];

            for (var i = 0; i < newColumns.Count; i++)
            {
                newFieldTypes[i] = newColumns[i].Type;
            }
            var newTupleDescriptor = TupleDescriptor.Create(newFieldTypes);

            var columnGroupCount = ColumnGroups.Count;
            var groups           = new List <ColumnGroup>(columnGroupCount + joined.ColumnGroups.Count);

            groups.AddRange(ColumnGroups);
            foreach (var g in joined.ColumnGroups)
            {
                var keys = new List <int>(g.Keys.Count);
                foreach (var i in g.Keys)
                {
                    keys.Add(columnCount + i);
                }
                var columns = new List <int>(g.Columns.Count);
                foreach (var i in g.Columns)
                {
                    columns.Add(columnCount + i);
                }
                groups.Add(new ColumnGroup(g.TypeInfoRef, keys, columns));
            }

            return(new RecordSetHeader(
                       newTupleDescriptor,
                       newColumns,
                       groups,
                       OrderTupleDescriptor,
                       Order));
        }
 /// <summary>
 /// Gets the <see cref="RecordSetHeader"/> object for the specified <paramref name="indexInfo"/>.
 /// </summary>
 /// <param name="indexInfo">The index info to get the header for.</param>
 /// <returns>The <see cref="RecordSetHeader"/> object.</returns>
 public static RecordSetHeader GetRecordSetHeader(this IndexInfo indexInfo)
 {
     return(RecordSetHeader.GetHeader(indexInfo));
 }
        /// <summary>
        /// Gets index of column with specified name.
        /// </summary>
        /// <param name="header">The header to search in.</param>
        /// <param name="columnName">Name of the column to get.</param>
        /// <returns>Index of the specified column.
        /// <see langword="-1" />, if there is no column with specified name.</returns>
        public static int IndexOf(this RecordSetHeader header, string columnName)
        {
            var column = (MappedColumn)header.Columns[columnName];

            return(column == null ? -1 : column.Index);
        }
        /// <summary>
        /// Converts the <see cref="IEnumerable{T}"/> of tuples to <see cref="Entity"/> instances.
        /// </summary>
        /// <param name="source">The tuples to process.</param>
        /// <param name="header">The record set header.</param>
        /// <param name="session">The session.</param>
        /// <param name="primaryKeyIndex">Index of primary key within the <see cref="Record"/>.</param>
        /// <returns>
        /// The sequence of <see cref="Entity"/> instances.
        /// </returns>
        public static IEnumerable <Entity> ToEntities(this IEnumerable <Tuple> source, RecordSetHeader header, Session session, int primaryKeyIndex)
        {
            var reader = session.Domain.RecordSetReader;

            foreach (var record in reader.Read(source, header, session))
            {
                var key = record.GetKey(primaryKeyIndex);
                if (key == null)
                {
                    continue;
                }
                var tuple = record.GetTuple(primaryKeyIndex);
                if (tuple != null)
                {
                    yield return(session.Handler.UpdateState(key, tuple).Entity);
                }
                else
                {
                    yield return(session.Query.SingleOrDefault(key));
                }
            }
        }
 /// <summary>
 /// Converts the <see cref="IEnumerable{T}"/> of tuples to <see cref="Entity"/> instances.
 /// </summary>
 /// <param name="source">The tuples to process.</param>
 /// <param name="header">The record set header.</param>
 /// <param name="primaryKeyIndex">Index of primary key within the <see cref="Record"/>.</param>
 /// <returns>
 /// The sequence of <see cref="Entity"/> instances.
 /// </returns>
 public static IEnumerable <T> ToEntities <T>(this IEnumerable <Tuple> source, RecordSetHeader header, Session session, int primaryKeyIndex)
     where T : class, IEntity
 {
     return(ToEntities(source, header, session, primaryKeyIndex).Cast <T>());
 }