Пример #1
0
        /// <summary>
        /// 检查 EntitySet 里的元素是还被销毁。
        /// </summary>
        /// <param name="property"></param>
        /// <param name="oldValue"></param>
        /// <param name="newValue"></param>
        /// <returns></returns>
        private bool CheckEntitySetDestroy(IProperty property, PropertyValue oldValue, PropertyValue newValue)
        {
            if (!property.Is <EntitySetProperty>())
            {
                return(false);
            }

            if (PropertyValue.IsEmpty(oldValue))
            {
                oldValue = ProcessSupposedProperty(property);
            }

            if (!PropertyValue.IsEmpty(oldValue) && PropertyValue.IsEmpty(newValue))
            {
                var oldSet = oldValue.GetValue() as IEntitySet;
                if (oldSet != null)
                {
                    oldSet.Clear();
                }

                if (!PropertyValue.IsEmpty(newValue))
                {
                    var newSet = newValue.GetValue() as IEntitySet;
                    if (newSet != null)
                    {
                        newSet.ShiftDetachedList(oldSet);
                    }
                }

                return(true);
            }

            return(false);
        }
Пример #2
0
        internal static void UpdateFromReference(IProperty property, IEntity entity, PropertyValue value)
        {
            var relationPro = property.As <RelationProperty>();

            if (relationPro == null || PropertyValue.IsEmpty(value) ||
                relationPro.RelationalPropertyType != RelationPropertyType.Entity)
            {
                return;
            }
            var refEntity   = value.GetValue().As <IEntity>();
            var relationKey = RelationshipUnity.GetRelationship(relationPro);

            if (relationKey == null)
            {
                return;
            }
            IEntity descEntity;
            IEntity sourceEntity;

            if (relationKey.Style == RelationshipStyle.One2Many)
            {
                descEntity   = entity;
                sourceEntity = refEntity;
            }
            else
            {
                descEntity   = refEntity;
                sourceEntity = entity;
            }
            foreach (var key in relationKey.Keys)
            {
                descEntity.SetValue(key.OtherProperty, sourceEntity.GetValue(key.ThisProperty));
            }
        }
Пример #3
0
 /// <summary>
 /// 清空并标识,将删除实体集中的所有对象。
 /// </summary>
 /// <param name="value"></param>
 internal static void SetEntitySetToNull(PropertyValue value)
 {
     if (PropertyValue.IsEmpty(value))
     {
         return;
     }
     value.GetValue().As <IEntitySet>(e => e.IsNeedClear = true);
 }
Пример #4
0
 /// <summary>
 /// 改为移除状态,确定该该实体删除。
 /// </summary>
 /// <param name="value"></param>
 internal static void SetEntityToNull(PropertyValue value)
 {
     if (PropertyValue.IsEmpty(value))
     {
         return;
     }
     value.GetValue().As <IEntity>(entity => entity.SetState(EntityState.Detached));
 }
Пример #5
0
        /// <summary>
        /// 安全地获取值。
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static object GetValueSafely(PropertyValue value)
        {
            if (value == Empty || value.StorageType == StorageType.Empty)
            {
                return(null);
            }

            return(value.GetValue());
        }
Пример #6
0
        /// <summary>
        /// 检查关联属性的空值,如果属性值已设置为null,则不应显示给客户端。
        /// </summary>
        /// <param name="property">要检查的属性。</param>
        /// <param name="value">属性的值。</param>
        /// <returns></returns>
        internal static PropertyValue CheckReturnValue(IProperty property, PropertyValue value)
        {
            var relationPro = property.As <RelationProperty>();

            if (relationPro == null || PropertyValue.IsEmpty(value))
            {
                return(value);
            }
            switch (relationPro.RelationalPropertyType)
            {
            case RelationPropertyType.Entity:
                return(CheckReturnEntityValue(value.GetValue().As <IEntity>(), value));

            case RelationPropertyType.EntitySet:
                return(CheckReturnEntitySetValue(value.GetValue() as IEntitySet, value));

            default:
                return(value);
            }
        }
Пример #7
0
 /// <summary>
 /// 判断是否为空。
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static bool IsEmpty(PropertyValue value)
 {
     return(value == Empty || value.StorageType == StorageType.Empty || value.GetValue() == null);
 }
Пример #8
0
 /// <summary>
 /// 获取指定 <see cref="PropertyValue"/> 真实的值。
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static object GetValue(PropertyValue value)
 {
     return(IsEmpty(value) ? null : value.GetValue());
 }
Пример #9
0
 /// <summary>
 /// 设置属性值。
 /// </summary>
 /// <param name="property"></param>
 /// <param name="value"></param>
 public override void SetValue(IProperty property, PropertyValue value)
 {
     property.Info.ReflectionInfo.SetValue(this, value.GetValue(), null);
 }