Exemplo n.º 1
0
        private object Read(Entity entity)
        {
            var refIdProperty = _columnInfo.Property as IRefIdProperty;

            if (refIdProperty != null)
            {
                object id = refIdProperty.Nullable ?
                            entity.GetRefNullableId(refIdProperty) : entity.GetRefId(refIdProperty);
                return(id);
            }

            var value = entity.GetProperty(_columnInfo.Property);

            return(value);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据SelectedValuePath指定的值,获取目标属性值
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static object GetSelectedValue(this SelectionViewMeta rvi, Entity entity)
        {
            var selectedValuePath = rvi.SelectedValuePath ?? Entity.IdProperty;

            //如果是一个引用属性,则返回引用属性的 Id
            var refProperty = selectedValuePath as IRefProperty;

            if (refProperty != null)
            {
                var meta = refProperty.GetMeta(entity);
                return(refProperty.Nullable ?
                       entity.GetRefNullableId(refProperty.RefIdProperty) :
                       entity.GetRefId(refProperty.RefIdProperty));
            }

            return(entity.GetProperty(selectedValuePath));
        }
        /// <summary>
        /// 归档当前实体所引用属性中需要归档的数据。
        /// </summary>
        /// <param name="entity">需要归档数据的实体,用于查询外键的值。</param>
        /// <param name="refTypeMeta">当前实体需要归档的引用属性的元数据信息。</param>
        /// <param name="level">表示递归尝试。</param>
        private void ArchivingReferenceData(Entity entity, EntityMeta refTypeMeta, int level = 1)
        {
            var properties = this.FindReferenceManagedProperty(refTypeMeta);

            foreach (var property in properties)
            {
                var foreignKeyValue = entity.GetRefId(((IRefEntityProperty)property.ManagedProperty).RefIdProperty);

                if (foreignKeyValue == null || foreignKeyValue.ToString() == "0")
                {
                    continue;
                }
#if DEBUG
                Console.WriteLine($"\tForeignKey: {foreignKeyValue}, Entity: {property.Name}");
#endif
                this.RecursiveQueryReferenceProperties(foreignKeyValue, property, level);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 根据SelectedValuePath指定的值,获取目标属性值
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static object GetSelectedValue(this SelectionViewMeta rvi, Entity entity)
        {
            var selectedValuePath = rvi.SelectedValuePath ?? Entity.IdProperty;

            //如果是一个引用属性,则返回引用属性的 Id
            var refProperty = selectedValuePath as IRefProperty;
            if (refProperty != null)
            {
                var meta = refProperty.GetMeta(entity);
                return refProperty.Nullable ?
                    entity.GetRefNullableId(refProperty.RefIdProperty) :
                    entity.GetRefId(refProperty.RefIdProperty);
            }

            return entity.GetProperty(selectedValuePath);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 尝试更新冗余属性值。
        /// </summary>
        internal void UpdateRedundancies(Entity entity)
        {
            //如果有一些在冗余属性路径中的属性的值改变了,则开始更新数据库的中的所有冗余字段的值。
            Entity dbEntity = null;
            var propertiesInPath = _repository.GetPropertiesInRedundancyPath();
            for (int i = 0, c = propertiesInPath.Count; i < c; i++)
            {
                var property = propertiesInPath[i];

                //如果只有一个属性,那么就是它变更引起的更新
                //否则,需要从数据库获取原始值来对比检测具体哪些属性值变更,然后再发起冗余更新。
                bool isChanged = c == 1;

                var refProperty = property as IRefIdProperty;
                if (refProperty != null)
                {
                    if (!isChanged)
                    {
                        if (dbEntity == null) { dbEntity = ForceGetById(entity); }
                        var dbId = dbEntity.GetRefId(refProperty);
                        var newId = entity.GetRefId(refProperty);
                        isChanged = !object.Equals(dbId, newId);
                    }

                    if (isChanged)
                    {
                        foreach (var path in property.InRedundantPathes)
                        {
                            //如果这条路径中是直接把引用属性的值作为值属性进行冗余,那么同样要进行值属性更新操作。
                            if (path.ValueProperty.Property == property)
                            {
                                this.UpdateRedundancyByRefValue(entity, path, refProperty);
                            }
                            //如果是引用变更了,并且只有一个 RefPath,则不需要处理。
                            //因为这个已经在属性刚变更时的处理函数中实时处理过了。
                            else if (path.RefPathes.Count > 1)
                            {
                                this.UpdateRedundancyByIntermidateRef(entity, path, refProperty);
                            }
                        }
                    }
                }
                else
                {
                    var newValue = entity.GetProperty(property);

                    if (!isChanged)
                    {
                        if (dbEntity == null) { dbEntity = ForceGetById(entity); }
                        var dbValue = dbEntity.GetProperty(property);
                        isChanged = !object.Equals(dbValue, newValue);
                    }

                    if (isChanged)
                    {
                        foreach (var path in property.InRedundantPathes)
                        {
                            UpdateRedundancyByValue(entity, path, newValue);
                        }
                    }
                }
            }

            entity.UpdateRedundancies = false;
        }