public virtual void Apply(IRelation relation, PropertyInfo prop)
        {
            DiscoverTargetTable(relation, prop);
            DiscoverJoinKeys(relation, prop);

            relation.Qualifier = _qualifier;
        }
Example #2
0
 private void DeclareOneToManyProperty(IRelation relation, XmlNode mapIntoNode)
 {
     cw.SimpleProperty(
         AccessLevel.Public,
         VirtualisationLevel.Virtual,
         String.Format("Iesi.Collections.Generic.ISet<{0}>", environment.ToTypeName(relation.ChildEntity, true)),
         relation.ParentName,
         true, true);
     // Mapping
     if (relation.Entity.Persistence.Persisted && relation.Entity2.Persistence.Persisted)
     {
         if (mapIntoNode == null)
         {
             return;
         }
         XmlNode refNode = map.CreateElement("set");
         map.AddAttribute("name", relation.ParentName);
         map.AddAttribute("table", relation.ChildEntity.Persistence.FullName);
         map.AddAttribute("inverse", "true");
         map.AddAttribute("lazy", "true");
         map.AddAttribute("cascade", RelationCascadeToNHValue(relation.Cascade));
         foreach (IAttribute a in relation.ChildAttributes)
         {
             XmlNode keyNode = map.CreateElement("key");
             map.AddAttribute("column", a.Persistence.Name);
             refNode.AppendChild(keyNode);
         }
         XmlNode relNode = map.CreateElement("one-to-many");
         map.AddAttribute("class", environment.ToTypeName(relation.ChildEntity.Type, true));
         refNode.AppendChild(relNode);
         mapIntoNode.AppendChild(refNode);
     }
 }
Example #3
0
        private void dgvConditions_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0 || e.RowIndex < 0)
            {
                return;
            }

            if (e.ColumnIndex == SelectColumnIndex ||
                e.ColumnIndex == RelationColumnIndex)
            {
                DataGridViewRow dgvr     = this.dgvConditions.Rows[e.RowIndex];
                bool            isSelect = Convert.ToBoolean(dgvr.Cells[SelectColumnIndex].Value);

                LogColumn lc       = LogColumnService.Instance.GetLogColumn(Convert.ToInt32(dgvr.Tag));
                IRelation relation = RelationService.Instance.GetRelation(lc.Type,
                                                                          Convert.ToString(dgvr.Cells[RelationColumnIndex].Value));

                dgvr.Cells[ColumnNameColumnIndex].ReadOnly        = true;
                dgvr.Cells[ColumnNameColumnIndex].Style.BackColor = SystemColors.Control;

                dgvr.Cells[RelationColumnIndex].ReadOnly        = !isSelect;
                dgvr.Cells[RelationColumnIndex].Style.BackColor = isSelect ? Color.White : SystemColors.Control;

                dgvr.Cells[ContentColumnIndex].ReadOnly        = !isSelect || relation.ParamsCount == 2;
                dgvr.Cells[ContentColumnIndex].Style.BackColor = (isSelect && relation.ParamsCount == 1)?Color.White : SystemColors.Control;

                dgvr.Cells[StartDateColumnIndex].ReadOnly        = !isSelect || relation.ParamsCount == 1;
                dgvr.Cells[StartDateColumnIndex].Style.BackColor = (isSelect && relation.ParamsCount == 2) ? Color.White : SystemColors.Control;

                dgvr.Cells[EndDateColumnIndex].ReadOnly        = !isSelect || relation.ParamsCount == 1;
                dgvr.Cells[EndDateColumnIndex].Style.BackColor = (isSelect && relation.ParamsCount == 2) ? Color.White : SystemColors.Control;
            }
        }
        public void Relation_Returns_Parent_Child_Object_Types_When_Creating()
        {
            IRelation r = CreateAndSaveRelation("Test", "test");

            Assert.AreEqual(Constants.ObjectTypes.Document, r.ParentObjectType);
            Assert.AreEqual(Constants.ObjectTypes.Media, r.ChildObjectType);
        }
Example #5
0
 /// <summary>
 /// Adds the given element to the collection
 /// </summary>
 /// <param name="item">The item to add</param>
 public override void Add(IModelElement item)
 {
     if ((this._parent.Impl == null))
     {
         IOperation implCasted = item.As <IOperation>();
         if ((implCasted != null))
         {
             this._parent.Impl = implCasted;
             return;
         }
     }
     if ((this._parent.InDirectionOf == null))
     {
         ITypedModel inDirectionOfCasted = item.As <ITypedModel>();
         if ((inDirectionOfCasted != null))
         {
             this._parent.InDirectionOf = inDirectionOfCasted;
             return;
         }
     }
     if ((this._parent.Relation == null))
     {
         IRelation relationCasted = item.As <IRelation>();
         if ((relationCasted != null))
         {
             this._parent.Relation = relationCasted;
             return;
         }
     }
 }
Example #6
0
        /// <summary>
        /// 从手中的牌生成所有可变的规则集合(3张)
        /// </summary>
        /// <param name="cards">手中的牌,或者包括当前摸的牌</param>
        /// <param name="filterCards">在生成的规则中,必须包含某几张牌的Id</param>
        /// <param name="includeCards">输出计算该规则包含的牌</param>
        /// <param name="parsers">解析规则列表</param>
        /// <returns></returns>
        public static IRelation[] BuildCustomVariableRelations(Card[] cards, Card[] filterCards, out Card[] outputCards, params ParserDefines[] parsers)
        {
            List <IRelation> relations    = new List <IRelation>();
            List <Card>      includeCards = new List <Card>();

            foreach (var cardArray in new NoneResolver().Resolve <Card>(cards, 3, filterCards))
            {
                IRelation relation = null;
                foreach (var parser in parsers)
                {
                    relation = ParserFactory.Instance(parser).Parse(cardArray);
                    if (relation != null)
                    {
                        break;
                    }
                }
                if (relation != null)
                {
                    relations.Add(relation);
                    for (var i = 0; i < relation.Cards.Length; i++)
                    {
                        if (!includeCards.Contains(relation.Cards[i]))
                        {
                            includeCards.Add(relation.Cards[i]);
                        }
                    }
                }
            }
            outputCards = includeCards.ToArray();
            return(relations.ToArray());
        }
 // Umbraco.Code.MapAll -ParentName -ChildName
 private static void Map(IRelation source, RelationDisplay target, MapperContext context)
 {
     target.ChildId    = source.ChildId;
     target.Comment    = source.Comment;
     target.CreateDate = source.CreateDate;
     target.ParentId   = source.ParentId;
 }
        /// <summary>
        /// Checks that the given content node has a relation to a media node, and creates a related media node if not
        /// </summary>
        /// <param name="node">The content node.</param>
        public void EnsureRelatedMediaNodeExists(IContent node)
        {
            try
            {
                int contentRoot = String.IsNullOrWhiteSpace(_config.ReadSetting("syncFromContentRootNode")) ? -1 : Convert.ToInt32(_config.ReadSetting("syncFromContentRootNode"));

                IContent contentRootNode = uMediaSyncHelper.contentService.GetById(contentRoot);

                if (contentRoot == -1 || node.Path.Contains(contentRootNode.Path))
                {
                    if (_config.SyncNode(node))
                    {
                        IRelation uMediaSyncRelation = uMediaSyncHelper.relationService.GetByParentId(node.Id).FirstOrDefault(r => r.RelationType.Alias == Constants.FolderRelationTypeAlias);

                        if (uMediaSyncRelation == null)
                        {
                            CreateRelatedMediaNode(node);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (!ex.Data.Contains("Content node id"))
                {
                    ex.Data.Add("Content node id", node.Id);
                }
                throw;
            }
        }
        public void TryMatchRelationType()
        {
            var dataSet         = new RelationRatingTestData.SingleMatchUsingSameTrait();
            var childTraits     = new RelationTraitCache.ChildTraits <float>(dataSet.FloatTraitValues);
            var childTraitsList = new List <RelationTraitCache.ChildTraits <float> > {
                childTraits, childTraits
            };
            var relationArray       = new IRelation <float>[] { m_FloatRelation, m_FloatRelation };
            var relationRatingsList = new List <Dictionary <RelationDataPair, float> >().Fill(2);
            var dataPairs           = new [] { new RelationDataPair(0, 1), new RelationDataPair(1, 0) };
            var memberRatings       = new []
            {
                // start with one of the members having no matches, to test the failure case
                TestUtils.RandomRatings(), new Dictionary <int, float>()
            };

            // this index resetting is normally done by the function that wraps this function
            RelationRatingTransform.CurrentRelationPairIndex = 0;
            Assert.False(RelationRatingTransform.RateMatches(relationArray, childTraitsList, dataPairs,
                                                             memberRatings, relationRatingsList));

            // give the member with no matches some matches, which should result in the whole type passing
            memberRatings[1] = TestUtils.RandomRatings();
            RelationRatingTransform.CurrentRelationPairIndex = 0;
            Assert.True(RelationRatingTransform.RateMatches(relationArray, childTraitsList, dataPairs,
                                                            memberRatings, relationRatingsList));

            VerifyRelationRatings(relationRatingsList[0], childTraits);
            VerifyRelationRatings(relationRatingsList[1], childTraits);
        }
Example #10
0
        public static Graph UniqueEntities(this Graph graph, Dictionary <Guid, IBHoMObject> replaceMap)
        {
            Dictionary <Guid, IBHoMObject> uniqueEntities = new Dictionary <Guid, IBHoMObject>();

            foreach (KeyValuePair <Guid, IBHoMObject> kvp in graph.Entities)
            {
                IBHoMObject unique = replaceMap[kvp.Key];
                if (!uniqueEntities.ContainsKey(unique.BHoM_Guid))
                {
                    uniqueEntities.Add(unique.BHoM_Guid, unique);
                }
            }

            graph.Entities = uniqueEntities;

            List <IRelation> uniqueRelations = new List <IRelation>();

            foreach (IRelation relation in graph.Relations)
            {
                IRelation relation1 = relation.UniqueEntities(replaceMap);

                //keep if it does not already exist
                if (!uniqueRelations.Any(r => r.Source.Equals(relation1.Source) && r.Target.Equals(relation1.Target)))
                {
                    uniqueRelations.Add(relation1);
                }
            }
            graph.Relations = uniqueRelations;
            return(graph);
        }
Example #11
0
        private ICollection <IField> GetAllFields(Type regType, Type subType)
        {
            List <IField> fields = GetFieldsIfManagedClass(regType, subType);

            Type[] superTypes = ReflectionUtils.GetSuperTypesWithInterfacesImplemented(regType,
                                                                                       new Type[]
                                                                                       { typeof(IReadOnlyEntity) });

            for (int i = 0; i < superTypes.Length; i++)
            {
                Type superType = superTypes[i];
                fields.AddRange(GetAllFields(superType, i > 0));
            }

            foreach (IField field in fields)
            {
                if (field is IRelation)
                {
                    IRelation relation = (IRelation)field;

                    if (relation.FetchStrategy == FetchStrategy.Default)
                    {
                        relation.FetchStrategy = _config.FetchStrategy;
                    }
                }
            }

            return(fields);
        }
Example #12
0
        private void CreateJoinExpressionForDefinedRelation(QueryBuildInfo buildInfo)
        {
            string    typeFromAlias = buildInfo.GetAlias(TypeFrom);
            IRelation relation      = processor.GetRelation(TypeFrom, TypeTo);

            if (relation == null)
            {
                relation = processor.GetRelation(TypeTo, TypeFrom);
            }

            if (relation != null)
            {
                Expr = JoinExpr.Build();
                ICollection <RelationColumnMapping> tableColumnMappings = relation.TableColumnMappings;
                int i = 0;
                foreach (RelationColumnMapping mapping in tableColumnMappings)
                {
                    if (i > 0)
                    {
                        Expr.And();
                    }
                    Expr.Field(TypeFrom, typeFromAlias, mapping.FromField);
                    Expr.Eq();
                    Expr.Field(TypeTo, TypeToAlias, mapping.ToField);
                    i++;
                }
            }
        }
Example #13
0
        public bool?LocateByRelation(ITestObject to, AutomationElement element)
        {
            IRelation relation = to.Relation;

            if (relation == null)
            {
                return(null);
            }

            ITestObject leftTO  = relation.Left;
            ITestObject rightTO = relation.Right;

            if (leftTO == null && rightTO == null)
            {
                return(null);
            }

            if (leftTO != null)
            {
                AutomationElement leftElement = UIAUtility.GetPreviousElement(element);
                if (!Match(leftTO, leftElement))
                {
                    return(false);
                }
            }
            if (rightTO != null)
            {
                AutomationElement rightElement = UIAUtility.GetNextElement(element);
                if (!Match(rightTO, rightElement))
                {
                    return(false);
                }
            }
            return(true);
        }
Example #14
0
 private void DeclareManyToOneProperty(IRelation relation, XmlNode mapIntoNode)
 {
     cw.SimpleProperty(
         AccessLevel.Public,
         VirtualisationLevel.Virtual,
         environment.ToTypeName(relation.ParentEntity.Type, true),
         relation.ChildName,
         true, true);
     // Mapping
     if (relation.Entity.Persistence.Persisted && relation.Entity2.Persistence.Persisted)
     {
         if (mapIntoNode == null)
         {
             return;
         }
         XmlNode refNode = map.CreateElement("many-to-one");
         map.AddAttribute("name", relation.ChildName);
         map.AddAttribute("class", environment.ToTypeName(relation.ParentEntity.Type, true));
         map.AddAttribute("cascade", RelationCascadeToNHValue(relation.Cascade));
         foreach (IAttribute a in relation.ChildAttributes)
         {
             XmlNode colNode = InitColumnNode(a);
             refNode.AppendChild(colNode);
         }
         mapIntoNode.AppendChild(refNode);
     }
 }
Example #15
0
        public static double RelationLength(this Graph graph, IRelation relation)
        {
            if (graph == null)
            {
                BH.Engine.Reflection.Compute.RecordError("Cannot query the relation length of a null graph.");
                return(0);
            }

            if (relation == null)
            {
                BH.Engine.Reflection.Compute.RecordError("Cannot query the relation length for a graph if the relation to query is null.");
                return(0);
            }

            double length = 0;

            if (relation.Curve != null)
            {
                length = relation.Curve.ILength();
            }
            else
            {
                IElement0D source = graph.Entities[relation.Source] as IElement0D;
                IElement0D target = graph.Entities[relation.Target] as IElement0D;
                length = source.IGeometry().Distance(target.IGeometry());
            }
            return(length);
        }
        protected virtual void DiscoverJoinKeys(IRelation relation, PropertyInfo prop)
        {
            var keyNames = BuildKeyNames(relation.Table);

            relation.JoinKey = relation.Table.PrimaryKey;
            relation.TargetJoinKey = FindColumnByNames(relation.TargetTable, keyNames);
        }
        public void UpdateRelatedEntitiesViolationDisabledReenabled()
        {
            TestDatabase database = new TestDatabase(false); // No identity
            IRelation    relation = database.AddMemberGroupRelation();

            database.Groups.Insert(new Group {
                Id = 1, Name = "Group 1"
            });
            database.Groups.Insert(new Group {
                Id = 2, Name = "Group 2"
            });
            database.Members.Insert(new Member {
                Id = "JD", Name = "John Doe", GroupId = 1
            });
            database.Members.Insert(new Member {
                Id = "MS", Name = "Michael Smith", GroupId = 2
            });

            relation.IsEnabled = false;
            database.Groups.Update(g => new Group {
                Id = g.Id + 1
            });

            relation.IsEnabled = true;
        }
Example #18
0
        private void CreateRelationColumns(IRelation relation)
        {
            EntityInfo relationInfo = CacheManager.GetEntityInfo(relation.RelatedObjectType);

            while (relationInfo != null)
            {
                ICollection <IColumn> relationKeys = relationInfo.GetKeys();
                foreach (IColumn relationKey in relationKeys)
                {
                    RelationColumnMapping matchingMapping = null;
                    foreach (RelationColumnMapping mapping in relation.TableColumnMappings)
                    {
                        if (mapping.ToField.Equals(relationKey.AttributeName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            matchingMapping = mapping;
                            break;
                        }
                    }

                    IColumn cloned = relationKey.Clone();
                    cloned.Key = false;
                    if (matchingMapping != null)
                    {
                        cloned.AttributeName = matchingMapping.FromField;
                        cloned.ColumnName    = AbstractColumn.PredictColumnName(matchingMapping.FromField);
                    }
                    cloned.Nullable = relation.Nullable;

                    _columns.Add(cloned);
                    _relationColumnInfoList.Add(new EntityRelationColumnInfo(cloned, relation, matchingMapping));
                }
                relationInfo = relationInfo.SuperEntityInfo;
            }
        }
Example #19
0
        public virtual void Apply(IRelation relation, PropertyInfo prop)
        {
            DiscoverTargetTable(relation, prop);
            DiscoverJoinKeys(relation, prop);

            relation.Qualifier = _qualifier;
        }
Example #20
0
        protected virtual void DiscoverJoinKeys(IRelation relation, PropertyInfo prop)
        {
            var keyNames = BuildKeyNames(relation.Table);

            relation.JoinKey       = relation.Table.PrimaryKey;
            relation.TargetJoinKey = FindColumnByNames(relation.TargetTable, keyNames);
        }
        private void WriteObjectProperty(IAttribute attribute, IEnvironmentHelper environment)
        {
            IRelation r       = attribute.UsedInRelations[0];
            IEntity   related = r.Entity;

            if (r.Entity == attribute.Entity)
            {
                related = r.Entity2;
            }

            cw.WriteLine("private {0} {1};",
                         environment.ToTypeName(related, true),
                         environment.ToMemberName(attribute));
            cw.BeginProperty(AccessLevel.Public,
                             VirtualisationLevel.Virtual,
                             environment.ToTypeName(related, true),
                             attribute.Name);
            cw.BeginPropertyGet();
            cw.WriteLine("return this.{0}.{1};",
                         PropertyName_DomainObjectProxy,
                         attribute.Name);
            cw.EndPropertyAccessor();
            cw.BeginPropertySet();
            cw.WriteLine("this.{0}.{1} = value;",
                         PropertyName_DomainObjectProxy,
                         attribute.Name);
            cw.EndPropertyAccessor();
            cw.EndProperty();
        }
Example #22
0
        public string CreateRelatedObjectsLoadQuery(IRelation relation)
        {
            var entityInfo = CacheManager.GetEntityInfo(relation.RelatedObjectType);

            var sb = new StringBuilder();

            sb.Append("SELECT * FROM ");
            sb.Append(entityInfo.TableInfo.TableName);
            sb.Append(" WHERE ");

            IEnumerator <RelationColumnMapping> enumerator = relation.TableColumnMappings.GetEnumerator();
            int i = 0;

            enumerator.Reset();
            while (enumerator.MoveNext())
            {
                RelationColumnMapping columnMapping = enumerator.Current;
                if (i != 0)
                {
                    sb.Append(" AND ");
                }
                sb.Append(entityInfo.FindColumnByAttribute(columnMapping.ToField).ColumnName);
                sb.Append("= ?");
                i++;
            }

            return(FixUpQuery(sb.ToString()));
        }
Example #23
0
        public IRelation Parse(params Card[] cards)
        {
            IRelation relation = null;

            if (cards.Length != 3)
            {
                return(relation);
            }
            if (cards[0].IsLarge != cards[1].IsLarge || cards[1].IsLarge != cards[2].IsLarge)
            {
                return(relation);
            }
            if (cards[0].Num + 2 == cards[2].Num && cards[1].Num + 1 == cards[2].Num)
            {
                if (cards[0].Num == 1)
                {
                    relation = cards[0].IsLarge ? new Relation123Big() : (IRelation) new Relation123Small();
                }
                relation = cards[0].IsLarge ? new RelationStraightBig() : (IRelation) new RelationStraightSmall();
            }
            if (cards[0].Num == 2 && cards[1].Num == 7 && cards[2].Num == 10)
            {
                relation = cards[0].IsLarge ? new Relation2710Big() : (IRelation) new Relation2710Small();
            }
            if (relation != null)
            {
                relation.Cards = cards;
            }
            return(relation);
        }
        /// <summary>
        /// Creates a relation between nodeForm and nodeTo in Neo4j.
        /// </summary>
        /// <param name="nodeFrom">Node From</param>
        /// <param name="relation">Type of the Edge</param>
        /// <param name="nodeTo">Node To</param>
        /// <returns></returns>
        public INode CreateRelation(INode nodeFrom, IRelation relation, INode nodeTo)
        {
            string tagFrom = nodeFrom.GetType().Name.ToLower();
            string tagTo   = nodeTo.GetType().Name.ToLower();

            _client.Cypher.Merge(toNode(nodeFrom)).Merge(toNode(nodeTo)).Merge($"({tagFrom})-{toRelation(relation)}->({tagTo})").ExecuteWithoutResultsAsync();
            return(nodeTo);
        }
Example #25
0
 public static Command AsCommand(this IRelation relation, string commandText)
 {
     return(new Command()
     {
         CommandText = commandText,
         Parameters = relation.AsParameters()
     });
 }
Example #26
0
 public static Query AsQuery(this IRelation relation, string queryText)
 {
     return(new Query()
     {
         QueryText = queryText,
         Parameters = relation.AsParameters()
     });
 }
Example #27
0
 public static ISet <IKey> Keys(this IRelation relation)
 {
     if (!allRelationsKeys.ContainsKey(relation))
     {
         allRelationsKeys[relation] = new HashSet <IKey>();
     }
     return(allRelationsKeys[relation]);
 }
Example #28
0
 public static IEnumerable <IConstraint> FromRelation(IRelation r)
 {
     return(r switch
     {
         ManyToMany m => new[] { (IConstraint) new ManyToManyConstraintTo(m), new ManyToManyConstraintFrom(m) },
         OneToMany o => new[] { new OneToManyConstraint(o) },
         ManyToOne m => new[] { new ManyToOneConstraint(m) }
     });
Example #29
0
        internal AggregateContainsRelationCollectionSpan(AggregateContainsRelationCollection parent, IRelation relation)
        {
            Requires.NotNull(parent, nameof(parent));
            Requires.NotNull(relation, nameof(relation));

            _parent  = parent;
            Relation = relation;
        }
        public String process(IRelation relation)
        {
            CommonTree root = parse();
            List <PlainItemDescription> idesc    = evaluatePlainItemDescription(ref root);
            PlainTextExporter           exporter = new PlainTextExporter(idesc, relation);
            String text = exporter.getText();

            return(text);
        }
        private RelationRepresentation CreateRepresentation(IRelation relation)
        {
            var parentLinkTemplate = GetLinkTemplate(relation.RelationType.ParentObjectType);
            var childLinkTemplate  = GetLinkTemplate(relation.RelationType.ChildObjectType);

            var rep = new RelationRepresentation(RelationLinkTemplate, parentLinkTemplate, childLinkTemplate);

            return(Mapper.Map(relation, rep));
        }
Example #32
0
        public ChildDataContainer(IRelation <T> relation)
        {
            if (relation == null)
            {
                throw new ArgumentException("Argument relation should not be null!");
            }

            _relation = relation;
        }
        private void UpdateFormFormGroupRelations(IRelation relation, bool isDelete)
        {
            var contentService = ApplicationContext.Current.Services.ContentService;
            var parentContent = contentService.GetById(relation.ParentId);

            string propertyAlias;

            switch (parentContent.ContentType.Alias)
            {
                case "Form":
                    propertyAlias = "associatedGroups";
                    break;
                case "FormGroup":
                    propertyAlias = "forms";
                    break;
                default:
                    throw new NotSupportedException(string.Format("Document type '{0}' not supported by Relation Type '{1}'.", parentContent.ContentType.Alias, relation.RelationType.Alias));
            }

            var propertyValue = parentContent.GetValue<string>(propertyAlias) ?? string.Empty;
            var propertyItems = propertyValue.ToDelimitedList();
            var currentItem = propertyItems.FirstOrDefault(x => x == relation.ChildId.ToString());

            if (isDelete && currentItem != null)
            {
                propertyItems.Remove(currentItem);
            }
            else if (!isDelete && currentItem == null)
            {
                propertyItems.Add(relation.ChildId.ToString());
            }
            else
            {
                return;
            }
            parentContent.SetValue(propertyAlias, string.Join(",", propertyItems));
            contentService.Save(parentContent);
            contentService.Publish(parentContent);
        }
 /// <summary>
 /// Gets the Parent object from a Relation as an <see cref="IUmbracoEntity"/>
 /// </summary>
 /// <param name="relation">Relation to retrieve parent object from</param>
 /// <param name="loadBaseType">Optional bool to load the complete object graph when set to <c>False</c></param>
 /// <returns>An <see cref="IUmbracoEntity"/></returns>
 public IUmbracoEntity GetParentEntityFromRelation(IRelation relation, bool loadBaseType = false)
 {
     var objectType = UmbracoObjectTypesExtensions.GetUmbracoObjectType(relation.RelationType.ParentObjectType);
     return _entityService.Get(relation.ParentId, objectType, loadBaseType);
 }
        /// <summary>
        /// Gets the Parent and Child objects from a Relation as a <see cref="Tuple"/>"/> with <see cref="IUmbracoEntity"/>.
        /// </summary>
        /// <param name="relation">Relation to retrieve parent and child object from</param>
        /// <param name="loadBaseType">Optional bool to load the complete object graph when set to <c>False</c></param>
        /// <returns>Returns a Tuple with Parent (item1) and Child (item2)</returns>
        public Tuple<IUmbracoEntity, IUmbracoEntity> GetEntitiesFromRelation(IRelation relation, bool loadBaseType = false)
        {
            var childObjectType = UmbracoObjectTypesExtensions.GetUmbracoObjectType(relation.RelationType.ChildObjectType);
            var parentObjectType = UmbracoObjectTypesExtensions.GetUmbracoObjectType(relation.RelationType.ParentObjectType);

            var child = _entityService.Get(relation.ChildId, childObjectType, loadBaseType);
            var parent = _entityService.Get(relation.ParentId, parentObjectType, loadBaseType);

            return new Tuple<IUmbracoEntity, IUmbracoEntity>(parent, child);
        }
 /// <summary>
 /// Deletes a <see cref="Relation"/>
 /// </summary>
 /// <param name="relation">Relation to Delete</param>
 public void Delete(IRelation relation)
 {
     var uow = _uowProvider.GetUnitOfWork();
     using (var repository = _repositoryFactory.CreateRelationRepository(uow))
     {
         repository.Delete(relation);
         uow.Commit();
     }
 }
        protected override void DiscoverJoinKeys(IRelation relation, PropertyInfo prop)
        {
            if (ThisClassContainsJoinKey)
            {
                relation.TargetJoinKey = relation.TargetTable.PrimaryKey;

                var keyNames = BuildKeyNames(relation.TargetTable);
                relation.JoinKey = FindColumnByNames(relation.Table, keyNames);
            }
            else
            {
                var keyNames = BuildKeyNames(relation.Table);
                relation.TargetJoinKey = FindColumnByNames(relation.TargetTable, keyNames);

                relation.JoinKey = relation.Table.PrimaryKey;
            }
        }
 public static Hashtable/*<Key,Value[]>*/ Compact(IRelation/*<Key,Value>*/ irel, Type value_type) 
 {
   Hashtable hash = new Hashtable();
   foreach(object key in irel.GetKeys()) 
   {
     ISet vals = irel.GetValues(key);
     if(vals.Count == 0)
       continue;
     System.Array array_vals = System.Array.CreateInstance(value_type, vals.Count);
     vals.CopyTo(array_vals, 0);
     if (typeof(Node).IsAssignableFrom(value_type)) 
     {
       Array.Sort(array_vals, DataStructUtil.NodeComparer);
     }
     hash.Add(key, array_vals);
   }
   return hash;
 }
 public virtual bool AddRelation(IRelation relation)
 {
   if(relation == null) return false;
   bool changed = false;
   foreach(object key in relation.GetKeys())
     if(this.AddAll(key, relation.GetValues(key)))
       changed = true;
   return changed;
 }
        protected override Type GetRelationType(IRelation relation, PropertyInfo prop)
        {
            if (!prop.PropertyType.IsGenericType)
            {
                throw new InvalidOperationException("Expecting a generic collection to use this property as one to many collection");
            }

            var relationType = prop.PropertyType.GetGenericArguments()[0];
            var listGeneric = typeof(List<>).MakeGenericType(relationType);

            if (!prop.PropertyType.IsAssignableFrom(listGeneric))
            {
                throw new InvalidOperationException("Expecting a collection type that is assignable from List<T> to use this propery as one to many collection");
            }

            return relationType;
        }
 protected abstract Type GetRelationType(IRelation relation, PropertyInfo prop);
 protected virtual void DiscoverTargetTable(IRelation relation, PropertyInfo prop)
 {
     relation.TargetType = GetRelationType(relation, prop);
     relation.TargetTable = relation.Table.Provider.FindOrCreateTable(relation.TargetType);
 }
 protected override Type GetRelationType(IRelation relation, PropertyInfo prop)
 {
     return prop.PropertyType;
 }
        private RelationRepresentation CreateRepresentation(IRelation relation)
        {
            var parentLinkTemplate = GetLinkTemplate(relation.RelationType.ParentObjectType);
            var childLinkTemplate = GetLinkTemplate(relation.RelationType.ChildObjectType);

            var rep = new RelationRepresentation(RelationLinkTemplate, parentLinkTemplate, childLinkTemplate);
            return Mapper.Map(relation, rep);
        }
 public virtual bool Accept(IRelation relation, PropertyInfo prop)
 {
     return true;
 }