Esempio n. 1
0
        internal override void LoadValueFromDb(object value, object exValue, LoadContext loadContext)
        {
            DataId              id                  = new DataId((string)DataProperty.EscapeFromDBNull(value));
            DataObject          dataObject          = (DataObject)null;
            DataObjectChildList dataObjectChildList = (DataObjectChildList)null;

            if (!id.IsEmpty)
            {
                MetadataAssociationRefList refs = this.Metadata.Association.Refs;
                MetadataAssociationRef     metadataAssociationRef = this.Metadata.Association.Selector == null ? refs[0] : refs.FindBySelectorValue(exValue);
                if (metadataAssociationRef == null)
                {
                    throw new DataException(string.Format("Нарушение целостности данных.\n{0}\nОшибка: Невозможно определить класс связанного объекта по значению селектора '{1}'.\n", (object)this.SystemView, exValue));
                }
                dataObject = this.Session[metadataAssociationRef.RefClass].EnsureCacheItem(id);
                if (dataObject.IsNull)
                {
                    dataObject = (DataObject)null;
                }
                else if (this.Metadata.IsAggregation)
                {
                    dataObjectChildList = dataObject.GetChilds(metadataAssociationRef.OwnerChildRef);
                    if ((loadContext & LoadContext.FetchAllObjects) != (LoadContext)0)
                    {
                        dataObjectChildList.SetCompleted(true);
                    }
                }
            }
            base.SetValue((object)dataObject);
            dataObjectChildList?.AttachChild(this.Object, true);
        }
        public DataProperty SelectSingleProperty(string path)
        {
            DataObject dataObject = this;
            int        startIndex = 0;

            while (true)
            {
                if (DataObject.Assigned(dataObject))
                {
                    int num = path.IndexOf('.', startIndex);
                    if (num >= 0)
                    {
                        string           memberName = path.Substring(startIndex, num - startIndex);
                        MetadataProperty property;
                        MetadataChildRef childRef;
                        dataObject.Class.NeedMember(memberName, out property, out childRef);
                        if (property != null)
                        {
                            dataObject = ((LinkProperty)dataObject[property]).Value;
                        }
                        else
                        {
                            DataObjectChildList childs = dataObject.GetChilds(childRef);
                            if (childs.Count != 0)
                            {
                                dataObject = childs[0];
                            }
                            else
                            {
                                goto label_6;
                            }
                        }
                        startIndex = num + 1;
                    }
                    else
                    {
                        goto label_9;
                    }
                }
                else
                {
                    break;
                }
            }
            return((DataProperty)null);

label_6:
            return((DataProperty)null);

label_9:
            if (startIndex > 0)
            {
                path = path.Substring(startIndex);
            }
            return(dataObject[path]);
        }
Esempio n. 3
0
        private void AssignValue(object value, bool isLoading)
        {
            bool                   isAggregation           = this.Metadata.IsAggregation;
            DataObject             dataObject1             = !isAggregation || !this.IsAssigned ? (DataObject)null : (DataObject)this.GetValue();
            MetadataAssociationRef metadataAssociationRef1 = (MetadataAssociationRef)null;
            DataObject             dataObject2             = (DataObject)value;

            if (!isLoading)
            {
                dataObject2 = this.Session.EnsureSessionObject(dataObject2);
            }
            if (DataObject.Assigned(dataObject2))
            {
                metadataAssociationRef1 = this.Metadata.Association.Refs.Find(dataObject2.Class);
                if (metadataAssociationRef1 == null)
                {
                    throw new DataException(string.Format("Попытка присвоить объект '{0}' свойству '{1}' объекта '{2}'", (object)dataObject2.Class.Name, (object)this.Metadata.Name, (object)this.Object.Class.Name));
                }
            }
            else
            {
                dataObject2 = (DataObject)null;
            }
            base.SetValue((object)dataObject2);
            if (!isAggregation || DataObject.SameObjects(dataObject2, dataObject1))
            {
                return;
            }
            if (DataObject.Assigned(dataObject1))
            {
                MetadataAssociationRef metadataAssociationRef2 = this.Metadata.Association.Refs.Need(dataObject1.Class);
                dataObject1.GetChilds(metadataAssociationRef2.OwnerChildRef).DetachChild(this.Object, isLoading);
            }
            if (DataObject.Assigned(dataObject2))
            {
                dataObject2.GetChilds(metadataAssociationRef1.OwnerChildRef).AttachChild(this.Object, isLoading);
            }
        }