Пример #1
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));
        }
        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]));
            }
        }