当前位置: 首页>>代码示例>>C#>>正文


C# DBObjectStream.AlterAttribute方法代码示例

本文整理汇总了C#中DBObjectStream.AlterAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# DBObjectStream.AlterAttribute方法的具体用法?C# DBObjectStream.AlterAttribute怎么用?C# DBObjectStream.AlterAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DBObjectStream的用法示例。


在下文中一共展示了DBObjectStream.AlterAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Update


//.........这里部分代码省略.........
                {
                    (elementsToBeAdded as IBaseEdge).Add(GraphDBTypeMapper.GetGraphObjectFromTypeName(attrDef.GetDBType(myDBContext.DBTypeManager).Name, (tupleElem.Value as ValueDefinition).Value.Value), tupleElem.Parameters.ToArray());
                }

                #endregion
            }
            else
            {
                #region References

                if (CollectionDefinition.CollectionType == CollectionType.SetOfUUIDs)
                {
                    var result = CollectionDefinition.TupleDefinition.GetAsUUIDEdge(myDBContext, attrDef);
                    if (result.Failed())
                    {
                        return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(result);
                    }
                    elementsToBeAdded = (IEdgeType)result.Value;
                }
                else
                {
                    if (AttributeIDChain.LastAttribute.EdgeType == null)
                    {
                        return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(new Error_InvalidEdgeType(AttributeIDChain.LastAttribute.GetType()));
                    }

                    var result = CollectionDefinition.TupleDefinition.GetCorrespondigDBObjectUUIDAsList(myGraphDBType, myDBContext, AttributeIDChain.LastAttribute.EdgeType.GetNewInstance(), AttributeIDChain.LastAttribute.GetDBType(myDBContext.DBTypeManager));
                    if (result.Failed())
                    {
                        return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(result);
                    }
                    elementsToBeAdded = (IEdgeType)result.Value;
                }

                #endregion

            }

            #region add elements

            if (elementsToBeAdded == null)
            {
                return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(new Error_UpdateAttributeNoElements(AttributeIDChain.LastAttribute));
            }

            if (myDBObjectStream.HasAttribute(AttributeIDChain.LastAttribute.UUID, attrDef.GetRelatedType(myDBContext.DBTypeManager)))
            {
                if (Assign)
                {

                    if (elementsToBeAdded is IReferenceEdge)
                    {
                        var oldEdge = ((IListOrSetEdgeType)myDBObjectStream.GetAttribute(AttributeIDChain.LastAttribute.UUID));
                        var removeRefExcept = RemoveBackwardEdgesOnReferences(this, (IReferenceEdge)oldEdge, myDBObjectStream, myDBContext);

                        if (!removeRefExcept.Success())
                        {
                            return new Exceptional<Dictionary<string,Tuple<TypeAttribute,IObject>>>(removeRefExcept.IErrors.First());
                        }
                    }

                    var alterResult = myDBObjectStream.AlterAttribute(AttributeIDChain.LastAttribute.UUID, elementsToBeAdded);
                    if (alterResult.Failed())
                    {
                        return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(alterResult);
                    }
                }
                else
                {
                    ((IListOrSetEdgeType)myDBObjectStream.GetAttribute(AttributeIDChain.LastAttribute.UUID)).UnionWith((IListOrSetEdgeType)elementsToBeAdded);
                }
            }
            else
            {
                myDBObjectStream.AddAttribute(AttributeIDChain.LastAttribute.UUID, elementsToBeAdded);
            }

            #region add backward edges

            if (AttributeIDChain.LastAttribute.GetDBType(myDBContext.DBTypeManager).IsUserDefined)
            {
                Dictionary<AttributeUUID, IObject> userdefinedAttributes = new Dictionary<AttributeUUID, IObject>();
                userdefinedAttributes.Add(AttributeIDChain.LastAttribute.UUID, elementsToBeAdded);

                var omm = new ObjectManipulationManager();
                var setBackEdgesExcept = omm.SetBackwardEdges(myGraphDBType, userdefinedAttributes, myDBObjectStream.ObjectUUID, myDBContext);

                if (setBackEdgesExcept.Failed())
                    return new Exceptional<Dictionary<String, Tuple<TypeAttribute, IObject>>>(setBackEdgesExcept);
            }

            #endregion

            attrsForResult.Add(AttributeIDChain.LastAttribute.Name, new Tuple<TypeAttribute, IObject>(AttributeIDChain.LastAttribute, elementsToBeAdded));
            return new Exceptional<Dictionary<string, Tuple<TypeAttribute, IObject>>>(attrsForResult);

            #endregion

            #endregion
        }
开发者ID:TheByte,项目名称:sones,代码行数:101,代码来源:AttributeAssignOrUpdateList.cs

示例2: ApplyAssignAttribute

        internal Exceptional<Tuple<String, TypeAttribute, IObject>> ApplyAssignAttribute(AAttributeAssignOrUpdate myAAttributeAssign, DBContext myDBContext, DBObjectStream myDBObject, GraphDBType myGraphDBType)
        {
            System.Diagnostics.Debug.Assert(myAAttributeAssign != null);

            //get value for assignement
            var aValue = myAAttributeAssign.GetValueForAttribute(myDBObject, myDBContext, myGraphDBType);
            if (aValue.Failed())
            {
                return new Exceptional<Tuple<String, TypeAttribute, IObject>>(aValue);
            }

            object oldValue = null;
            IObject newValue = aValue.Value;

            if (myDBObject.HasAttribute(myAAttributeAssign.AttributeIDChain.LastAttribute.UUID, myGraphDBType))
            {

                #region Update the value because it already exists

                oldValue = myDBObject.GetAttribute(myAAttributeAssign.AttributeIDChain.LastAttribute, myGraphDBType, myDBContext).Value;

                switch (myAAttributeAssign.AttributeIDChain.LastAttribute.KindOfType)
                {
                    case KindsOfType.SetOfReferences:
                        var typeOfCollection = ((AttributeAssignOrUpdateList)myAAttributeAssign).CollectionDefinition.CollectionType;

                        if (typeOfCollection == CollectionType.List)
                            return new Exceptional<Tuple<String, TypeAttribute, IObject>>(new Error_InvalidAssignOfSet(myAAttributeAssign.AttributeIDChain.LastAttribute.Name));

                        var removeRefExcept = RemoveBackwardEdgesOnReferences(myAAttributeAssign, (IReferenceEdge)oldValue, myDBObject, myDBContext);

                        if (!removeRefExcept.Success())
                            return new Exceptional<Tuple<String, TypeAttribute, IObject>>(removeRefExcept.IErrors.First());

                        newValue = (ASetOfReferencesEdgeType)newValue;
                        break;

                    case KindsOfType.SetOfNoneReferences:
                    case KindsOfType.ListOfNoneReferences:
                        newValue = (IBaseEdge)newValue;
                        break;

                    case KindsOfType.SingleNoneReference:
                        if (!(oldValue as ADBBaseObject).IsValidValue((newValue as ADBBaseObject).Value))
                        {
                            return new Exceptional<Tuple<string, TypeAttribute, IObject>>(new Error_DataTypeDoesNotMatch((oldValue as ADBBaseObject).ObjectName, (newValue as ADBBaseObject).ObjectName));
                        }
                        newValue = (oldValue as ADBBaseObject).Clone((newValue as ADBBaseObject).Value);
                        break;

                    case KindsOfType.SingleReference:
                        if (newValue is ASingleReferenceEdgeType)
                        {
                            removeRefExcept = RemoveBackwardEdgesOnReferences(myAAttributeAssign, (IReferenceEdge)oldValue, myDBObject, myDBContext);

                            if (!removeRefExcept.Success())
                                return new Exceptional<Tuple<String, TypeAttribute, IObject>>(removeRefExcept.IErrors.First());

                            ((ASingleReferenceEdgeType)oldValue).Merge((ASingleReferenceEdgeType)newValue);
                            newValue = (ASingleReferenceEdgeType)oldValue;
                        }
                        break;

                    case KindsOfType.SpecialAttribute: // Special attributes can't be updated currently

                        if ((newValue as DBString) != null && (newValue as DBString).CompareTo(oldValue) == 0)
                        {
                            return new Exceptional<Tuple<string, GraphDB.TypeManagement.TypeAttribute, GraphDB.TypeManagement.IObject>>(new Tuple<string, GraphDB.TypeManagement.TypeAttribute, GraphDB.TypeManagement.IObject>(myAAttributeAssign.AttributeIDChain.LastAttribute.Name, myAAttributeAssign.AttributeIDChain.LastAttribute, newValue as IObject));
                        }
                        else
                        {
                            return new Exceptional<Tuple<String, TypeAttribute, IObject>>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                        }

                        break;

                    default:
                        return new Exceptional<Tuple<String, TypeAttribute, IObject>>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                }

                #endregion

            }

            var alterExcept = myDBObject.AlterAttribute(myAAttributeAssign.AttributeIDChain.LastAttribute.UUID, newValue);

            if (alterExcept.Failed())
                return new Exceptional<Tuple<string, TypeAttribute, IObject>>(alterExcept);

            if (!alterExcept.Value)
            {
                myDBObject.AddAttribute(myAAttributeAssign.AttributeIDChain.LastAttribute.UUID, newValue);
            }

            #region add backward edges

            if (myAAttributeAssign.AttributeIDChain.LastAttribute.GetDBType(myDBContext.DBTypeManager).IsUserDefined)
            {
                Dictionary<AttributeUUID, IObject> userdefinedAttributes = new Dictionary<AttributeUUID, IObject>();
                userdefinedAttributes.Add(myAAttributeAssign.AttributeIDChain.LastAttribute.UUID, newValue);
//.........这里部分代码省略.........
开发者ID:Vadi,项目名称:sones,代码行数:101,代码来源:AAttributeAssignOrUpdate.cs


注:本文中的DBObjectStream.AlterAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。