public static DataEntity AddParent(this DataEntity source, IRelationshipDefinition rel,
                                           DataEntity parent)
        {
            ValidateParentRelationship(source, parent, rel);

            var relationshipName = rel.FullName;

            return(source.AddParent(relationshipName, parent));
        }
Ejemplo n.º 2
0
 private static RelationshipDefinition ConvertToConcrete(IRelationshipDefinition rd)
 {
     return(new RelationshipDefinition
     {
         Description = rd.Description,
         FullName = rd.FullName,
         Name = rd.Name,
         ThisObjectDefinitionFullName = rd.ThisObjectDefinitionFullName,
         RelatedObjectDefinitionFullName = rd.RelatedObjectDefinitionFullName,
         RelatedProperties = rd.RelatedProperties,
         RelationshipType = rd.RelationshipType,
         ThisProperties = rd.ThisProperties
     });
 }
        private static void ValidateChildRelationship(DataEntity source, IRelationshipDefinition rel)
        {
            ValidateRelationship(rel);
            if (rel.RelationshipType != RelationshipType.Child)
            {
                throw new InvalidOperationException("Adding children must be to a relationship that is defined as type Child.");
            }

            var sourceType = source.ObjectDefinitionFullName;

            if (rel.ThisObjectDefinitionFullName != sourceType)
            {
                throw new InvalidOperationException(string.Format("Attempting to add a relationship to type {0}, but the relationship is defined for type {1}.", sourceType, rel.ThisObjectDefinitionFullName));
            }
        }
        public static DataEntity AddChildren(this DataEntity source, IRelationshipDefinition rel,
                                             IEnumerable <DataEntity> children)
        {
            ValidateChildRelationship(source, rel);
            var childList = children as List <DataEntity> ?? new List <DataEntity>(children);

            foreach (var entity in childList)
            {
                if (entity.ObjectDefinitionFullName != rel.RelatedObjectDefinitionFullName)
                {
                    throw new InvalidOperationException(string.Format("Each entity in the collection of children must be of type {0}, but at least one was of type {1}.", rel.RelatedObjectDefinitionFullName, entity.ObjectDefinitionFullName));
                }
            }

            return(source.AddChildren(rel.FullName, childList));
        }
        private static void ValidateRelationship(IRelationshipDefinition relationshipDefinition)
        {
            if (relationshipDefinition == null)
            {
                throw new ArgumentNullException("relationshipDefinition", "RelationshipDefinition cannot be null.");
            }

            if (string.IsNullOrWhiteSpace(relationshipDefinition.FullName))
            {
                throw new InvalidOperationException("RelationshipDefinition's FullName must not be null or whitespace.");
            }

            if (string.IsNullOrWhiteSpace(relationshipDefinition.Name))
            {
                throw new InvalidOperationException("RelationshipDefinition's Name must not be null or whitespace.");
            }

            if (relationshipDefinition.FullName.Contains("."))
            {
                throw new InvalidOperationException("The Relationship's name must not contain a '.'.");
            }
        }
        private static void ValidateParentRelationship(DataEntity source, DataEntity parent, IRelationshipDefinition rel)
        {
            ValidateRelationship(rel);
            if (rel.RelationshipType != RelationshipType.Parent)
            {
                throw new InvalidOperationException("Adding a parent must be to a relationship that is defined as type Parent.");
            }

            var sourceType = source.ObjectDefinitionFullName;

            if (rel.ThisObjectDefinitionFullName != sourceType)
            {
                throw new InvalidOperationException(string.Format("Attempting to add a relationship to type {0}, but the relationship is defined for type {1}.", sourceType, rel.ThisObjectDefinitionFullName));
            }
            var relatedType = rel.RelatedObjectDefinitionFullName;
            var parentType  = parent.ObjectDefinitionFullName;

            if (parentType != relatedType)
            {
                throw new InvalidOperationException(string.Format("When adding a parent using a relationship, the type of the parent [{0}] must match the type defined on the relationship [{1}]", parentType, relatedType));
            }
        }
        private static DataEntity AddChildrenWithLazyValidation(this DataEntity source, IRelationshipDefinition rel,
                                                                IEnumerable <DataEntity> children)
        {
            ValidateChildRelationship(source, rel);
            var validatingAction     = ValidateNames(rel.RelatedObjectDefinitionFullName);
            var validatingEnumerable = children.ValidateEnumerable(validatingAction);

            return(source.AddChildren(rel.FullName, validatingEnumerable));
        }
        public static DataEntity AddParent <T>(this DataEntity source, IRelationshipDefinition rel, T parent, Func <T, DataEntity> converter)
        {
            var converted = converter(parent);

            return(source.AddParent(rel, converted));
        }
        public static DataEntity AddChildren <T>(this DataEntity source, IRelationshipDefinition rel, IEnumerable <T> children, Func <T, DataEntity> converter)
        {
            var dataEntites = children.Select(converter);

            return(source.AddChildren(rel, dataEntites));
        }