当前位置: 首页>>代码示例>>C#>>正文


C# Row.NewRow方法代码示例

本文整理汇总了C#中Row.NewRow方法的典型用法代码示例。如果您正苦于以下问题:C# Row.NewRow方法的具体用法?C# Row.NewRow怎么用?C# Row.NewRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Row的用法示例。


在下文中一共展示了Row.NewRow方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetEntities

        internal IEnumerable<Row> GetEntities(Row schema, CompressionContext compression)
        {
            for (int i = 0; i < Records.Length; i++)
            {
                var record = Records[i];

                short fixedOffset = 0;
                short variableColumnIndex = 0;
                int columnIndex = 0;
                var readState = new RecordReadState();
                var dataRow = schema.NewRow();

                foreach (DataColumn col in dataRow.Columns)
                {
                    var sqlType = SqlTypeFactory.Create(col, readState, compression);
                    object columnValue = null;

                    if (sqlType.IsVariableLength)
                    {
                        if (!record.HasNullBitmap || !record.NullBitmap[columnIndex])
                        {
                            // If a nullable varlength column does not have a value, it may be not even appear in the varlength column array if it's at the tail
                            if (record.VariableLengthColumnData.Count <= variableColumnIndex)
                                columnValue = sqlType.GetValue(new byte[] { });
                            else
                                columnValue = sqlType.GetValue(record.VariableLengthColumnData[variableColumnIndex].GetBytes().ToArray());
                        }

                        variableColumnIndex++;
                    }
                    else
                    {
                        // Must cache type FixedLength as it may change after getting a value (e.g. SqlBit)
                        short fixedLength = sqlType.FixedLength.Value;

                        if (!record.HasNullBitmap || !record.NullBitmap[columnIndex])
                            columnValue = sqlType.GetValue(record.FixedLengthData.Skip(fixedOffset).Take(fixedLength).ToArray());

                        fixedOffset += fixedLength;
                    }

                    columnIndex++;
                    dataRow[col] = columnValue;
                }

                yield return dataRow;
            }
        }
开发者ID:Robin--,项目名称:OrcaMDF,代码行数:48,代码来源:NonclusteredIndexPage.cs

示例2: GetEntities

        internal override IEnumerable<Row> GetEntities(Row schema)
        {
            foreach (var record in page.Records)
            {
                // Don't process forwarded blob fragments as they should only be processed from the referenced record
                if (record.Type == RecordType.BlobFragment)
                    continue;

                short fixedOffset = 0;
                short variableColumnIndex = 0;
                short nonSparseColumnIndex = 0;
                var readState = new RecordReadState();
                var dataRow = schema.NewRow();

                foreach (DataColumn col in dataRow.Columns)
                {
                    var sqlType = SqlTypeFactory.Create(col, readState, compression);
                    object columnValue = null;

                    // Sparse columns needs to retrieve their values from the sparse vector, contained in the very last
                    // variable length column in the record.
                    if (col.IsSparse)
                    {
                        // We may encounter records that don't have any sparse vectors, for instance if no sparse columns have values
                        if (record.SparseVector != null)
                        {
                            // Column ID's are stored as ints in general. In the sparse vector though, they're stored as shorts.
                            if (record.SparseVector.ColumnValues.ContainsKey((short)col.ColumnID))
                                columnValue = sqlType.GetValue(record.SparseVector.ColumnValues[(short)col.ColumnID]);
                        }
                    }
                    else
                    {
                        // Before we even try to parse the column & make a null bitmap lookup, ensure that it's present in the record.
                        // There may be columns > record.NumberOfColumns caused by nullable columns added to the schema after the record was written.
                        if (nonSparseColumnIndex < record.NumberOfColumns)
                        {
                            if (sqlType.IsVariableLength)
                            {
                                // If there's either no null bitmap, or the null bitmap defines the column as non-null.
                                if (!record.HasNullBitmap || !record.NullBitmap[nonSparseColumnIndex])
                                {
                                    // If the current variable length column index exceeds the number of stored
                                    // variable length columns, the value is empty by definition (that is, 0 bytes, but not null).
                                    if (variableColumnIndex < record.NumberOfVariableLengthColumns)
                                        columnValue = sqlType.GetValue(record.VariableLengthColumnData[variableColumnIndex].GetBytes().ToArray());
                                    else
                                        columnValue = sqlType.GetValue(new byte[0]);
                                }

                                variableColumnIndex++;
                            }
                            else
                            {
                                // Must cache type FixedLength as it may change after getting a value (e.g. SqlBit)
                                short fixedLength = sqlType.FixedLength.Value;

                                if (!record.HasNullBitmap || !record.NullBitmap[nonSparseColumnIndex])
                                {
                                    byte[] valueBytes = record.FixedLengthData.Skip(fixedOffset).Take(fixedLength).ToArray();

                                    // We may run out of fixed length bytes. In certain conditions a null integer may have been added without
                                    // there being a null bitmap. In such a case, we detect the null condition by there not being enough fixed
                                    // length bytes to process.
                                    if (valueBytes.Length > 0)
                                        columnValue = sqlType.GetValue(valueBytes);
                                }

                                fixedOffset += fixedLength;
                            }

                            // Sparse columns don't have an entry in the null bitmap, thus we should only increment it if the current
                            // column was not a sparse column.
                            nonSparseColumnIndex++;
                        }
                    }

                    dataRow[col] = columnValue;
                }

                yield return dataRow;
            }
        }
开发者ID:Robin--,项目名称:OrcaMDF,代码行数:83,代码来源:PrimaryRecordEntityParser.cs


注:本文中的Row.NewRow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。