Beispiel #1
0
        public DmView(DmTable table, IEnumerable <DmRow> rows)
        {
            if (table == null)
            {
                return;
            }

            this.Table = table.Clone();
            this.internalFilter(null, rows);
        }
Beispiel #2
0
        public DmView(DmTable table, Predicate <DmRow> filter = null)
        {
            if (table == null)
            {
                return;
            }

            this.internalFilter(filter, table.Rows);
            this.Table = table.Clone();
        }
Beispiel #3
0
        public DmView(DmTable table, DmRowState state)
        {
            if (table == null)
            {
                return;
            }

            Predicate <DmRow> filter = new Predicate <DmRow>(r => r.RowState == state);

            this.internalFilter(filter, table.Rows);

            this.Table = table.Clone();
        }
Beispiel #4
0
        DmTable MergeSchema(DmTable table)
        {
            if (dataTable == null)
            {
                dataTable = table.Clone();

                if (dataTable.DmSet != null)
                {
                    dataTable.DmSet.Tables.Add(dataTable);
                }
            }
            else
            {
                // Do the columns
                int oldCount = dataTable.Columns.Count;
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    DmColumn src  = table.Columns[i];
                    DmColumn dest = (dataTable.Columns.Contains(src.ColumnName, true)) ? dataTable.Columns[src.ColumnName] : null;

                    // If columns doesn't exist, create it
                    if (dest == null)
                    {
                        dest = src.Clone();
                        dataTable.Columns.Add(dest);
                    }
                }

                // check the PrimaryKey
                DmColumn[] targetPKey = dataTable.PrimaryKey.Columns;
                DmColumn[] tablePKey  = table.PrimaryKey.Columns;
                if (targetPKey.Length != tablePKey.Length)
                {
                    if (tablePKey.Length != 0)
                    {
                        throw new Exception("Merge Failed, keys are differents");
                    }

                    // special case when the target table does not have the PrimaryKey
                    if (targetPKey.Length == 0)
                    {
                        DmColumn[] key = new DmColumn[tablePKey.Length];
                        for (int i = 0; i < tablePKey.Length; i++)
                        {
                            key[i] = dataTable.Columns[tablePKey[i].ColumnName];
                        }

                        dataTable.PrimaryKey = new DmKey(key);
                    }
                }
                else
                {
                    // Check the keys are same
                    for (int i = 0; i < targetPKey.Length; i++)
                    {
                        if (!table.IsEqual(targetPKey[i].ColumnName, tablePKey[i].ColumnName))
                        {
                            throw new Exception("Merge Failed, keys are differents");
                        }
                    }
                }
            }

            return(dataTable);
        }