Exemplo n.º 1
0
        protected Relation GetConcreteRelation(MemberInfo subject)
        {
            var declaredMany = subject.GetPropertyOrFieldType().DetermineCollectionElementType();

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

            var implementorsOfMany = DomainInspector.GetBaseImplementors(declaredMany).ToArray();

            if (implementorsOfMany.Length != 1)
            {
                // short
                return(null);
            }

            var declaredOne       = subject.ReflectedType;
            var implementorsOfOne = DomainInspector.GetBaseImplementors(declaredOne).ToArray();

            if (implementorsOfOne.Length != 1)
            {
                return(null);
            }

            return(new Relation(implementorsOfOne[0], implementorsOfMany[0]));
        }
Exemplo n.º 2
0
        public bool Match(MemberInfo subject)
        {
            var  propertyType = subject.GetPropertyOrFieldType();
            Type many         = propertyType.DetermineCollectionElementType();

            Type one = subject.DeclaringType;

            if (many == null)
            {
                return(false);
            }
            if (one.Equals(many))
            {
                // Circular references
                return(false);
            }
            CascadeOn?applyCascade = DomainInspector.ApplyCascade(one, subject, many);

            if (applyCascade.HasValue && !applyCascade.Value.Has(CascadeOn.DeleteOrphans) &&
                !applyCascade.Value.Has(CascadeOn.Remove) && !applyCascade.Value.Has(CascadeOn.All))
            {
                return(false);
            }
            if (!DomainInspector.IsEntity(many))
            {
                return(false);
            }
            if (DomainInspector.IsTablePerClass(many) && !DomainInspector.IsRootEntity(many))
            {
                return(false);
            }
            return(base.Match(new Relation(one, many)));
        }
 protected bool HasMultipleCollectionOf(Type collectionOwner, Type elementType, ref int collectionCount)
 {
     foreach (var propertyType in collectionOwner.GetProperties(PublicPropertiesOfClassHierarchy).Where(p => DomainInspector.IsPersistentProperty(p)).Select(p => p.PropertyType))
     {
         if (!propertyType.Equals(elementType) && DomainInspector.IsComponent(propertyType))
         {
             if (HasMultipleCollectionOf(propertyType, elementType, ref collectionCount))
             {
                 return(true);
             }
         }
         else
         {
             var propertyElementType = propertyType.DetermineCollectionElementOrDictionaryValueType();
             if (elementType.Equals(propertyElementType))
             {
                 collectionCount++;
             }
         }
         if (collectionCount > 1)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 4
0
        public override bool Match(MemberInfo subject)
        {
            // does not match even when an explicit cascade is provided by DomainInspector
            var relation = GetRelation(subject);

            return(relation != null && !DomainInspector.ApplyCascade(relation.From, subject, relation.To).HasValue&& base.Match(relation));
        }
        public override bool Match(MemberInfo subject)
        {
            var relation = GetRelation(subject);

            if (relation == null || !DomainInspector.IsEntity(relation.To))
            {
                return(false);
            }

            return(base.Match(subject));
        }
Exemplo n.º 6
0
        protected virtual string GetKeyColumnName(PropertyPath subject)
        {
            // Note: in a double usage of a collection of children the user can choose to solve it
            // using a different 'key-column' or a specific 'where-clause'.
            // Is better to delegate this responsibility case-by-case to a customizer instead use a general pattern.
            // In case of unidirectional relation the UnidirectionalOneToManyMultipleCollectionsKeyColumnApplier is available
            Type propertyType          = subject.LocalMember.GetPropertyOrFieldType();
            Type childType             = propertyType.DetermineCollectionElementType();
            var  entity                = subject.GetContainerEntity(DomainInspector);
            var  parentPropertyInChild = DomainInspector.GetBidirectionalMember(entity, subject.LocalMember, childType) ?? childType.GetFirstPropertyOfType(entity);
            var  baseName              = parentPropertyInChild == null ? subject.PreviousPath == null ? entity.Name : entity.Name + subject.PreviousPath : parentPropertyInChild.Name;

            return(GetKeyColumnName(baseName));
        }
Exemplo n.º 7
0
        protected virtual string GetColumnNameForRelation(PropertyPath subject)
        {
            var relation = GetRelation(subject.LocalMember);
            var fromMany = relation.From;

            if (!DomainInspector.IsEntity(fromMany))
            {
                fromMany = subject.GetContainerEntity(DomainInspector);
            }
            var toMany         = relation.To;
            var baseColumnName = toMany.GetPoidColumnName();

            return(fromMany != toMany ? baseColumnName : string.Format("{0}_{1}", subject.ToColumnName("_"), baseColumnName));
        }
Exemplo n.º 8
0
        protected virtual string GetColumnNameForRelation(PropertyPath subject)
        {
            var relation = GetRelation(subject.LocalMember);
            var fromMany = relation.From;

            if (!DomainInspector.IsEntity(fromMany))
            {
                fromMany = subject.GetContainerEntity(DomainInspector);
            }
            var toMany         = relation.To;
            var baseColumnName = toMany.Name + "Id";

            if (fromMany != toMany)
            {
                return(baseColumnName);
            }
            return(subject.ToColumnName() + baseColumnName);
        }
Exemplo n.º 9
0
        protected virtual string GetManyToManyTableName(PropertyPath subject)
        {
            var  manyToManyRelation = GetRelation(subject.LocalMember);
            var  fromMany           = manyToManyRelation.From;
            var  toMany             = manyToManyRelation.To;
            bool fromIsMaster       = DomainInspector.IsMasterManyToMany(fromMany, toMany);
            bool toIsMaster         = DomainInspector.IsMasterManyToMany(toMany, fromMany);

            fromMany = subject.GetContainerEntity(DomainInspector);
            string[] names;
            if (fromIsMaster == toIsMaster)
            {
                names = (from t in (new[] { fromMany, toMany }) orderby t.Name select t.Name).ToArray();
            }
            else
            {
                names = fromIsMaster ? new[] { fromMany.Name, toMany.Name } : new[] { toMany.Name, fromMany.Name };
            }
            return(GetTableNameForRelation(names));
        }
Exemplo n.º 10
0
        public override bool Match(MemberInfo subject)
        {
            if (!base.Match(subject))
            {
                return(false);
            }

            var concreteRelation = GetConcreteRelation(subject);

            if (concreteRelation == null)
            {
                return(false);
            }
            var one  = concreteRelation.From;
            var many = concreteRelation.To;

            if (one.Equals(many))
            {
                // Circular references
                return(false);
            }

            Cascade?applyCascade = GetExplicitPolymorphismCascade(subject);

            if (applyCascade.HasValue && !applyCascade.Value.Has(Cascade.DeleteOrphans) &&
                !applyCascade.Value.Has(Cascade.Remove) && !applyCascade.Value.Has(Cascade.All))
            {
                return(false);
            }
            if (!DomainInspector.IsEntity(many))
            {
                return(false);
            }
            if (DomainInspector.IsTablePerClass(many) && !DomainInspector.IsRootEntity(many))
            {
                return(false);
            }

            return(true);
        }
        protected virtual string GetManyToManyTableName(PropertyPath subject)
        {
            var  manyToManyRelation = GetRelation(subject.LocalMember);
            var  fromMany           = manyToManyRelation.From;
            var  toMany             = manyToManyRelation.To;
            bool fromIsMaster       = DomainInspector.IsMasterManyToMany(fromMany, toMany);
            bool toIsMaster         = DomainInspector.IsMasterManyToMany(toMany, fromMany);

            fromMany = subject.GetContainerEntity(DomainInspector);
            var explicitBidirectionalMember = DomainInspector.GetBidirectionalMember(fromMany, subject.LocalMember, toMany);

            if (explicitBidirectionalMember == null)
            {
                Relation[] twoRelations = GetTwoRelation(fromMany, fromIsMaster, toMany, toIsMaster);
                return(GetTableNameForRelation(twoRelations[0], twoRelations[1]));
            }
            else
            {
                RelationOn[] twoRelationOn = GetTwoRelationOn(fromMany, fromIsMaster, subject, toMany, toIsMaster, explicitBidirectionalMember);
                return(GetTableNameForRelationOnProperty(twoRelationOn[0], twoRelationOn[1]));
            }
        }
 private bool IsUnidirectionalOneToMany(Type from, Type to)
 {
     return(DomainInspector.IsOneToMany(from, to) && to.GetFirstPropertyOfType(from, p => DomainInspector.IsPersistentProperty(p)) == null);
 }
Exemplo n.º 13
0
        protected virtual bool KeyIsElement(Type memberType, MemberInfo subject)
        {
            var mapKey = memberType.DetermineDictionaryKeyType();

            return(!DomainInspector.IsManyToMany(subject.ReflectedType, mapKey) && !DomainInspector.IsComponent(mapKey));
        }