예제 #1
0
        /// <summary>
        /// 判断本实例更变的值与被比实体对应值是否相等
        /// </summary>
        /// <param name="objEntity">被比较实体</param>
        /// <returns>是否相等</returns>
        public bool EqualsModify(EntityObjectBase objEntity)
        {
            if (objEntity.GetType() != this.GetType())
            {
                return(false);
            }

            TableAttributes taEntity = objEntity.GetEntityColumns();
            TableAttributes taThis   = this.GetEntityColumns();

            bool bEquals = true;

            for (int i = 0; i < taEntity.Columns.Count; i++)
            {
                ColumnAttributes caEntity = taEntity.Columns[i] as ColumnAttributes;
                ColumnAttributes caThis   = taThis.Columns[i] as ColumnAttributes;
                if (caThis.IsModify && (caEntity.Value.ToString() != caThis.Value.ToString()))
                {
                    bEquals = false;
                    break;
                }
            }

            return(bEquals);
        }
예제 #2
0
        /// <summary>
        /// 将指定实体修改过的值同步到本实例
        /// </summary>
        /// <param name="objEntity">同步实体</param>
        public void SynchronizeModifyValue(EntityObjectBase objEntity)
        {
            TableAttributes taEntity = objEntity.GetEntityColumns();

            foreach (ColumnAttributes caCurrent in taEntity.Columns)
            {
                if (true == caCurrent.IsModify)
                {
                    SetMappingValue(this, caCurrent.ColumnName, caCurrent.Value);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 取实体映射的数据库表信息
        /// </summary>
        /// <param name="objEntity">实体对像</param>
        /// <returns>映射表信息</returns>
        public static TableAttributes GetEntityColumns(EntityObjectBase objEntity)
        {
            TableAttributes taEntity = new TableAttributes();

            #region 取表名称

            object[] objTable = objEntity.GetType().GetCustomAttributes(typeof(TableMapping), false);
            if (objTable.Length > 0)
            {
                if (objTable[0] is TableMapping)
                {
                    TableMapping tmCurrent = objTable[0] as TableMapping;
                    taEntity.TableName = tmCurrent.TableName;
                }
            }

            #endregion

            #region 取字段名称

            foreach (PropertyInfo pi in objEntity.GetType().GetProperties())
            { // 根据属性映射创建表模式并记录属性值
                object[] objColumn = pi.GetCustomAttributes(typeof(ColumnMapping), false);
                if (objColumn.Length > 0)
                {
                    if (objColumn[0] is ColumnMapping)
                    {
                        if (pi.CanRead)
                        {
                            ColumnMapping    attrCurrent = objColumn[0] as ColumnMapping;
                            ColumnAttributes caCurrent   = new ColumnAttributes();

                            caCurrent.ColumnName      = attrCurrent.ColumnName;
                            caCurrent.IsIdentity      = attrCurrent.IsIdentity;
                            caCurrent.IsPrimaryKey    = attrCurrent.IsPrimaryKey;
                            caCurrent.IsVersionNumber = attrCurrent.IsVersionNumber;
                            caCurrent.Value           = pi.GetValue(objEntity, null);
                            caCurrent.OriginalValue   = objEntity.table.Rows[0][attrCurrent.ColumnName];
                            if (caCurrent.OriginalValue.ToString() != caCurrent.Value.ToString())
                            {
                                caCurrent.IsModify = true;
                            }

                            taEntity.Columns.Add(caCurrent);
                        }
                    }
                }
            }

            #endregion

            return(taEntity);
        }