Exemplo n.º 1
0
 string[] IEntity.GetModifiedProperties()
 {
     return((from s in InnerEntry.GetModifiedProperties()
             let p = PropertyUnity.GetProperty(_entityType, s)
                     where p != null && (!p.Info.IsPrimaryKey || (p.Info.IsPrimaryKey && p.Info.GenerateType == IdentityGenerateType.None))
                     select s).ToArray());
 }
        private void RemoveInnerItemEntry(TInner innerItem, InnerEntry innerEntry)
        {
            innerEntry.ReferenceCount--;

            if (innerEntry.ReferenceCount == 0)
            {
                _innerEntries.Remove(innerItem);
            }
        }
Exemplo n.º 3
0
        public BashkraEntry()
        {
            InitializeComponent();

            InnerEntry.Focused   += InnerEntryOnFocused;
            InnerEntry.Unfocused += InnerEntryOnFocused;

            GestureRecognizers.Add(new TapGestureRecognizer {
                Command = new Command(() => InnerEntry.Focus())
            });
        }
Exemplo n.º 4
0
        /// <summary>
        /// 检查并懒加载属性的值。
        /// </summary>
        /// <param name="property"></param>
        /// <returns></returns>
        private PropertyValue CheckAndLazyPropertyValue(IProperty property)
        {
            var value = PropertyValue.Empty;

            if (InnerEntry.Has(property.Name))
            {
                value = InnerEntry[property.Name].GetOldValue();
            }

            return(PropertyValue.IsEmpty(value) ? ProcessSupposedProperty(property) : value);
        }
        private void AddInnerItemEntry(TInner innerItem, TKey innerItemKey)
        {
            InnerEntry innerEntry;

            if (!_innerEntries.TryGetValue(innerItem, out innerEntry))
            {
                innerEntry = new InnerEntry(innerItemKey);
                _innerEntries[innerItem] = innerEntry;
            }

            innerEntry.ReferenceCount++;
        }
        void OnInnerRemove(object sender, int index, IEnumerable <TInner> oldItems)
        {
            foreach (var innerItem in oldItems)
            {
                InnerEntry innerEntry = _innerEntries[innerItem];

                RemoveInnerItemFromAllOuterEntriesMatchingKey(innerItem, innerEntry.Key);

                RemoveInnerItemFromKeyLookup(innerItem, innerEntry.Key);

                RemoveInnerItemEntry(innerItem, innerEntry);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 检查是否有原值相等。
        /// </summary>
        /// <param name="property"></param>
        /// <param name="value"></param>
        /// <param name="oldValue"></param>
        /// <returns></returns>
        private bool CheckValueEquals(IProperty property, PropertyValue value, out PropertyValue oldValue)
        {
            if (InnerEntry.Has(property.Name) &&
                (oldValue = (this as IEntity).GetDirectValue(property)) != null)
            {
                oldValue.InitializeInstanceName(string.Empty);
                return(value == oldValue);
            }

            oldValue = PropertyValue.Empty;

            return(false);
        }
Exemplo n.º 8
0
        void IEntity.NotifyModified(string propertyName)
        {
            InnerEntry.Modify(propertyName);

            if (state == EntityState.Unchanged)
            {
                state = EntityState.Modified;
            }

            if (owner != null)
            {
                owner.Parent.As <IEntity>(s => s.NotifyModified(owner.Property == null ? string.Empty : owner.Property.Name));
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 内部设置属性值的方法。
        /// </summary>
        /// <param name="property"></param>
        /// <param name="value"></param>
        private void InternalSetValue(IProperty property, PropertyValue value)
        {
            if (PropertyValue.IsEmpty(value))
            {
                if (SetNullable(property))
                {
                    return;
                }
            }

            if (property is RelationProperty)
            {
                InnerLazyMgr.SetValueCreated(property.Name);
            }

            InnerEntry.Modify(property.Name, value);
        }
Exemplo n.º 10
0
        void IEntityRelation.NotifyModified(string propertyName)
        {
            if (!string.IsNullOrEmpty(propertyName))
            {
                InnerEntry.Modify(propertyName);
            }

            if (_state == EntityState.Unchanged)
            {
                _state = EntityState.Modified;
            }

            //修改父对象的状态
            if (_owner != null)
            {
                _owner.Parent.As <IEntityRelation>(s => s.NotifyModified(_owner.Property == null ? string.Empty : _owner.Property.Name));
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 处理附加属性的值。
        /// </summary>
        /// <param name="property"></param>
        /// <returns></returns>
        private PropertyValue ProcessSupposedProperty(IProperty property)
        {
            if (property is RelationProperty relationProperty &&
                relationProperty.Options.LoadBehavior != LoadBehavior.None)
            {
                var value = EntityLazyloader.Load(this, relationProperty);

                if (value != null && !PropertyValue.IsEmpty(value))
                {
                    InnerLazyMgr.SetValueCreated(property.Name);
                    value._dataType = property.Info.DataType;
                    InnerEntry.Initializate(property.Name, value);
                }

                return(value);
            }

            return(PropertyValue.Empty);
        }
Exemplo n.º 12
0
        void IEntity.NotifyModified(string propertyName, bool modified)
        {
            if (!modified)
            {
                InnerEntry.Modify(propertyName, false);
                return;
            }

            InnerEntry.Modify(propertyName, modified);

            if (_state == EntityState.Unchanged)
            {
                _state = EntityState.Modified;
            }

            if (_owner != null)
            {
                _owner.Parent.As <IEntity>(s => s.NotifyModified(_owner.Property == null ? string.Empty : _owner.Property.Name));
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// 处理附加属性的值。
        /// </summary>
        /// <param name="property"></param>
        /// <returns></returns>
        private PropertyValue ProcessSupposedProperty(IProperty property)
        {
            var relationProperty = property.As <RelationProperty>();

            if (relationProperty != null &&
                relationProperty.Options.LoadBehavior != LoadBehavior.None)
            {
                var value = EntityLazyloader.Load(this, relationProperty);
                InnerLazyMgr.SetValueCreated(property.Name);

                if (value != null)
                {
                    InnerEntry.Initializate(property.Name, value, () => value.DataType = property.Info.DataType);
                }

                return(value);
            }

            return(PropertyValue.Empty);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 克隆出一个新的实体对象。
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            var entity = _entityType.New <EntityObject>();

            entity.InitializeInstanceName((this.As <IEntityPersistentInstanceContainer>().InstanceName));
            entity.InitializeEnvironment(_environment);

            if (_entityType.IsNotCompiled())
            {
                foreach (var property in PropertyUnity.GetProperties(_entityType))
                {
                    var pv = GetValue(property);
                    entity.SetValue(property, pv);
                }
            }
            else
            {
                this.TryLockModifing(() =>
                {
                    InnerEntry.ForEach(k =>
                    {
                        var property = PropertyUnity.GetProperty(_entityType, k.Key);
                        if (property?.Info.IsPrimaryKey == true)
                        {
                            entity.InnerEntry.Initializate(k.Key, k.Value.GetCurrentValue());
                        }
                        else
                        {
                            entity.InnerEntry.Modify(k.Key, k.Value.GetCurrentValue());
                        }
                    });
                });
            }

            return(entity);
        }
Exemplo n.º 15
0
 PropertyValue IEntity.GetDirectValue(IProperty property)
 {
     return(InnerEntry.Has(property.Name) ? InnerEntry[property.Name].GetCurrentValue() : PropertyValue.Empty);
 }
Exemplo n.º 16
0
 bool IEntity.IsModified(string propertyName)
 {
     return(InnerEntry.Has(propertyName) && InnerEntry[propertyName].IsModified);
 }
Exemplo n.º 17
0
 PropertyValue IEntity.GetOldValue(IProperty property)
 {
     return(InnerEntry.Has(property.Name) ? InnerEntry[property.Name].GetOldValue() : PropertyValue.Empty);
 }
Exemplo n.º 18
0
 void IEntity.ResetUnchanged()
 {
     _state = EntityState.Unchanged;
     InnerEntry.Reset();
 }