Example #1
0
        public override object CopyNativeAs(Schema.IDataType dataType)
        {
            // We need to construct a new TableVar here because otherwise the native table
            // will be constructed with the keys inferred for the source, resulting in
            // incorrect access plans (see Defect #33978 for more).
            Schema.ResultTableVar tableVar = new Schema.ResultTableVar(Node);
            tableVar.Owner = Program.Plan.User;
            tableVar.EnsureTableVarColumns();
            Program.EnsureKey(tableVar);

            if (!Active)
            {
                Open();
            }
            else
            {
                Reset();
            }

            NativeTable nativeTable = new NativeTable(Manager, tableVar);

            while (Next())
            {
                using (IRow row = Select())
                {
                    nativeTable.Insert(Manager, row);
                }
            }

            return(nativeTable);
        }