コード例 #1
0
        internal override int SaveValueToDb(ref object value, ref object exValue)
        {
            if (!this.IsAssigned)
            {
                throw new DataException("Попытка записать в БД неприсвоенное значение.");
            }
            MetadataAssociationRefList refs = this.Metadata.Association.Refs;
            DataObject dataObject           = (DataObject)base.GetValue();

            if (dataObject != null && !dataObject.IsNull)
            {
                value = (object)dataObject.Id.ToString();
                if (this.Metadata.Association.Selector != null)
                {
                    exValue = InDbUtils.Convert((object)refs.Need(dataObject.Class).SelectorValue, this.Metadata.Association.Selector.DataType);
                }
            }
            return(this.Metadata.Association.Selector != null ? 2 : 1);
        }
コード例 #2
0
            public SqlUtils.NavigationStep EnsureRootStep(string path)
            {
                SqlUtils.NavigationStep navigationStep1 = !string.IsNullOrEmpty(path) ? this.FindRootStep(path) : throw new ArgumentNullException(nameof(path));
                if (navigationStep1 != null)
                {
                    return(navigationStep1);
                }
                string        predecessorPath;
                string        identifier;
                MetadataClass refClass1;
                bool          isExternalRef;

                SqlUtils.Navigation.ParseLastPartOfPath(this.Class.Metadata.Classes, path, out predecessorPath, out identifier, out refClass1, out isExternalRef);
                SqlUtils.NavigationStep predecessor = !string.IsNullOrEmpty(predecessorPath) ? this.EnsureRootStep(predecessorPath) : (SqlUtils.NavigationStep)null;
                MetadataClass           refClass2   = predecessor != null ? predecessor.TargetClass : this.Class;

                SqlUtils.NavigationStep navigationStep2;
                if (isExternalRef)
                {
                    MetadataProperty metadataProperty = refClass1.Properties.Need(identifier);
                    if (!metadataProperty.IsLink)
                    {
                        throw new Exception(string.Format("Свойство \"{0}.{1}\" не является отношением.", (object)refClass1.Name, (object)identifier));
                    }
                    navigationStep2 = (SqlUtils.NavigationStep) new SqlUtils.ExternalAssociationNavigationStep(this, predecessor, path, metadataProperty.Association.Refs.Need(refClass2));
                }
                else
                {
                    MetadataProperty property;
                    MetadataChildRef childRef;
                    refClass2.NeedMember(identifier, out property, out childRef);
                    if (property != null)
                    {
                        if (!property.IsLink)
                        {
                            throw new DataException(string.Format("\"{0}\" не является ассоциацией или дочерним объектом.", (object)identifier));
                        }
                        MetadataAssociationRefList refs = property.Association.Refs;
                        if (refClass1 == null && refs.Count != 1)
                        {
                            throw new DataException(string.Format("\"{0}\" является ассоциацией с вариантами связи. В тексте запроса такое поле следует указывать в форме \"имя-свойства:имя-связанного-класса\" (например, \"Subject:Person\").", (object)identifier));
                        }
                        navigationStep2 = (SqlUtils.NavigationStep) new SqlUtils.AssociationNavigationStep(this, predecessor, path, refClass1 == null ? refs[0] : refs.Need(refClass1));
                    }
                    else
                    {
                        navigationStep2 = (SqlUtils.NavigationStep) new SqlUtils.ChildNavigationStep(this, predecessor, path, childRef);
                    }
                }
                navigationStep2.TargetAlias = this.CreateUniqueAlias(navigationStep2.TargetClass.DataTable);
                this.RootSteps.Add(navigationStep2);
                return(navigationStep2);
            }