示例#1
0
        /// <summary>
        /// Clone the current DmSet schema. No rows are imported
        /// </summary>
        public virtual DmSet Clone()
        {
            DmSet ds = new DmSet
            {
                DmSetName     = this.DmSetName,
                CaseSensitive = this.CaseSensitive,
                Culture       = this.Culture
            };

            for (int i = 0; i < Tables.Count; i++)
            {
                DmTable dt = Tables[i].Clone();
                ds.Tables.Add(dt);
            }

            List <DmRelation> rels = Relations;

            for (int i = 0; i < rels.Count; i++)
            {
                DmRelation rel = rels[i].Clone(ds);
                ds.Relations.Add(rel);
            }

            return(ds);
        }
示例#2
0
        internal void MergeDmSet(DmSet source)
        {
            if (source == dataSet)
            {
                return;                              //somebody is doing an 'automerge'
            }
            List <DmColumn> existingColumns = null;  // need to cache existing columns

            existingColumns = new List <DmColumn>(); // need to cache existing columns
            foreach (DmTable dt in dataSet.Tables)
            {
                foreach (DmColumn dc in dt.Columns)
                {
                    existingColumns.Add(dc);
                }
            }


            for (int i = 0; i < source.Tables.Count; i++)
            {
                MergeTableData(source.Tables[i]); // since column expression might have dependency on relation, we do not set
                //column expression at this point. We need to set it after adding relations
            }

            foreach (DmTable sourceTable in source.Tables)
            {
                DmTable targetTable;
                targetTable = dataSet.Tables.First(s => s.TableName == sourceTable.TableName);
            }
        }
示例#3
0
        /// <summary>
        /// Copies both the structure and data for this DmSet
        /// </summary>
        /// <returns></returns>
        public DmSet Copy()
        {
            DmSet dsNew = Clone();

            foreach (DmTable table in this.Tables)
            {
                DmTable destTable = dsNew.Tables.First(t => t.TableName == table.TableName);

                foreach (DmRow row in table.Rows)
                {
                    table.ImportRow(row);
                }
            }

            return(dsNew);
        }
示例#4
0
        public DmSet GetChanges(DmRowState rowStates)
        {
            DmSet dsNew = null;

            if (0 != (rowStates & ~(DmRowState.Added | DmRowState.Deleted | DmRowState.Modified | DmRowState.Unchanged)))
            {
                throw new Exception($"InvalidRowState {rowStates}");
            }

            // Initialize all the individual table bitmaps.
            TableChanges[] bitMatrix = new TableChanges[Tables.Count];

            for (int i = 0; i < bitMatrix.Length; ++i)
            {
                bitMatrix[i] = new TableChanges(Tables[i].Rows.Count);
            }

            // find all the modified rows and their parents
            MarkModifiedRows(bitMatrix, rowStates);

            // copy the changes to a cloned table
            for (int i = 0; i < bitMatrix.Length; ++i)
            {
                Debug.Assert(0 <= bitMatrix[i].HasChanges, "negative change count");
                if (0 < bitMatrix[i].HasChanges)
                {
                    if (dsNew == null)
                    {
                        dsNew = this.Clone();
                    }

                    DmTable table     = this.Tables[i];
                    DmTable destTable = dsNew.Tables.First(t => t.TableName == table.TableName);

                    for (int j = 0; 0 < bitMatrix[i].HasChanges; ++j)
                    { // Loop through the rows.
                        if (bitMatrix[i][j])
                        {
                            destTable.ImportRow(table.Rows[j]);
                            bitMatrix[i].HasChanges--;
                        }
                    }
                }
            }
            return(dsNew);
        }
示例#5
0
        internal DmRelation Clone(DmSet destination)
        {
            DmTable parent    = destination.Tables[ParentTable.TableName];
            DmTable child     = destination.Tables[ChildTable.TableName];
            int     keyLength = parentKey.Columns.Length;

            DmColumn[] parentColumns = new DmColumn[keyLength];
            DmColumn[] childColumns  = new DmColumn[keyLength];

            for (int i = 0; i < keyLength; i++)
            {
                parentColumns[i] = parent.Columns[ParentKey.Columns[i].ColumnName];
                childColumns[i]  = child.Columns[ChildKey.Columns[i].ColumnName];
            }

            DmRelation clone = new DmRelation(RelationName, parentColumns, childColumns);

            return(clone);
        }
 internal DmTableCollection(DmSet set)
 {
     this.innerSet = set;
 }
示例#7
0
 public DmRelationCollection(DmSet dmSet)
 {
     this.dmSet = dmSet;
 }