Example #1
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);
        }
Example #2
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;
        }