/// <summary>
        /// Get tablesnapshot by name
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public TableSnapshot GetTableSnapshot(string tableName)
        {
            //
            // Initialize result
            TableSnapshot result = new TableSnapshot(tableName);


            //
            // Get list of primary keys
            // For each primary key
            // Try to get it's properties in entity
            // Then add to hasTable
            DbSet dbSet = this._mapDatabase.GetTable(tableName);

            dbSet.Load();
            List <string> listPrimaryKeys = this._mapDatabase.GetPrimaryKeyName(tableName);
            List <GroupUniqueColumnInformation> listGroupUniqueInformation = this._mapDatabase.GetGroupUniqueColumnInformation(tableName);
            TypeAccessor typeAccessor = this._mapDatabase.GetTableTypeAccessor(tableName);


            //
            // Foreach record in database
            // Try to get RecordSnapshot
            foreach (object record in dbSet)
            {
                RecordSnapshot recordSnapshot = new RecordSnapshot();

                //
                // Get primary key value
                foreach (string primaryKey in listPrimaryKeys)
                {
                    PrimaryKeySnapshot primaryKeySnapshot = new PrimaryKeySnapshot(primaryKey, typeAccessor[record, primaryKey]);
                    recordSnapshot.Add(primaryKeySnapshot);
                }


                //
                // Get unqiue column value
                foreach (GroupUniqueColumnInformation groupUnique in listGroupUniqueInformation)
                {
                    GroupUniqueColumnSnapshot groupUniqueSnapshot = new GroupUniqueColumnSnapshot(groupUnique.ConstraintName);
                    foreach (UniqueColumnInformation uniqueColumnInfo in groupUnique.ListUniqueColumn)
                    {
                        UniqueColumnSnapshot uniqueColumnSnapshot = new UniqueColumnSnapshot(uniqueColumnInfo.ColumnName, typeAccessor[record, uniqueColumnInfo.ColumnName]);
                        groupUniqueSnapshot.Add(uniqueColumnSnapshot);
                    }
                    recordSnapshot.Add(groupUniqueSnapshot);
                }


                result.Add(recordSnapshot);
            }


            //
            // Return result
            return(result);
        }
        public override bool Equals(object obj)
        {
            //
            // Initialize result
            bool result = false;


            //
            // Check
            if (obj is PrimaryKeySnapshot)
            {
                PrimaryKeySnapshot pkSnapshot = (PrimaryKeySnapshot)obj;
                if (pkSnapshot.Name == this.Name && pkSnapshot.Value.Equals(this.Value))
                {
                    result = true;
                }
            }

            //
            // Return result
            return(result);
        }
Пример #3
0
 /// <summary>
 /// Add new primarykey snapshot (primarykey name and primarykey value)
 /// </summary>
 /// <param name="primaryKeySnapshot"></param>
 public void Add(PrimaryKeySnapshot primaryKeySnapshot)
 {
     this._listPrimaryKeySnapshot.Add(primaryKeySnapshot);
 }
 /// <summary>
 /// Add new primarykey snapshot (primarykey name and primarykey value)
 /// </summary>
 /// <param name="primaryKeySnapshot"></param>
 public void Add(PrimaryKeySnapshot primaryKeySnapshot)
 {
     this._listPrimaryKeySnapshot.Add(primaryKeySnapshot);
 }
        /// <summary>
        /// Get tablesnapshot by name
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public TableSnapshot GetTableSnapshot(string tableName)
        {
            //
            // Initialize result
            TableSnapshot result = new TableSnapshot(tableName);

            //
            // Get list of primary keys
            // For each primary key
            // Try to get it's properties in entity
            // Then add to hasTable
            DbSet dbSet = this._mapDatabase.GetTable(tableName);
            dbSet.Load();
            List<string> listPrimaryKeys = this._mapDatabase.GetPrimaryKeyName(tableName);
            List<GroupUniqueColumnInformation> listGroupUniqueInformation = this._mapDatabase.GetGroupUniqueColumnInformation(tableName);
            TypeAccessor typeAccessor = this._mapDatabase.GetTableTypeAccessor(tableName);

            //
            // Foreach record in database
            // Try to get RecordSnapshot
            foreach (object record in dbSet)
            {
                RecordSnapshot recordSnapshot = new RecordSnapshot();

                //
                // Get primary key value
                foreach (string primaryKey in listPrimaryKeys)
                {
                    PrimaryKeySnapshot primaryKeySnapshot = new PrimaryKeySnapshot(primaryKey, typeAccessor[record, primaryKey]);
                    recordSnapshot.Add(primaryKeySnapshot);
                }

                //
                // Get unqiue column value
                foreach (GroupUniqueColumnInformation groupUnique in listGroupUniqueInformation)
                {
                    GroupUniqueColumnSnapshot groupUniqueSnapshot = new GroupUniqueColumnSnapshot(groupUnique.ConstraintName);
                    foreach (UniqueColumnInformation uniqueColumnInfo in groupUnique.ListUniqueColumn)
                    {
                        UniqueColumnSnapshot uniqueColumnSnapshot = new UniqueColumnSnapshot(uniqueColumnInfo.ColumnName, typeAccessor[record, uniqueColumnInfo.ColumnName]);
                        groupUniqueSnapshot.Add(uniqueColumnSnapshot);
                    }
                    recordSnapshot.Add(groupUniqueSnapshot);
                }

                result.Add(recordSnapshot);
            }

            //
            // Return result
            return result;
        }