Exemplo n.º 1
0
                public static RelationSide createRelationSide(Type targetClass, string fieldName, RelationSideQuantifier quantifier)
                {
                    RelationSide rs = new RelationSide();

                    rs.targetClass = targetClass;
                    rs.fieldName   = fieldName;
                    rs.quantifier  = quantifier;
                    //тут еще должно быть присвоение филдинфо через создание sampleObject

                    return(rs);
                }
Exemplo n.º 2
0
            public string asLeftJoinQueryPart(string mySideEntityName)
            {
                //возвращает предикат left join для этого relation для использования в селект-запросах

                RelationSide mrs = getMyRelationSide(mySideEntityName);

                RelationSide ors = getAnotherRelationSide(mySideEntityName);

                string s = string.Format("left join {0} on {1}.{2} = {3}.{4}", ors.tableName, mrs.tableName, mrs.fieldName, ors.tableName, ors.fieldName); // + тут должна быть другая таблица, значит, надо передавать myside

                return(s);
            }
Exemplo n.º 3
0
        public static string SideToNameSuffix(RelationSide side)
        {
            switch (side)
            {
            case RelationSide.Left:
                return("");

            case RelationSide.Right:
                return("2");

            default:
                return(Enum.GetName(typeof(RelationSide), side));
            }
        }
Exemplo n.º 4
0
            public RelationSide getAnotherRelationSide(IKeepable sampleObject)
            {
                //определяет сторону, которую занимает переданный объект, и возвращает другую

                RelationSide rls = getRealtionSideByClassName(sampleObject.entityType);

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

                if (rls.relationSideQualifier == "A")
                {
                    return(B);
                }
                else
                {
                    return(A);
                }
            }
Exemplo n.º 5
0
            public RelationSide getAnotherRelationSide(string mySideEntityName)
            {
                //определяет сторону, которую занимает переданный объект, и возвращает другую

                RelationSide rls = getRealtionSideByClassName(mySideEntityName);

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

                if (rls.relationSideQualifier == "A")
                {
                    return(B);
                }
                else
                {
                    return(A);
                }
            }
Exemplo n.º 6
0
            public bool isMyRelation_where_im_obligatory(IKeepable sampleObject)
            {
                //определяет, является ли sampleObject той стороной этого relation, где он обязателен

                RelationSide rs = getRealtionSideByClassName(sampleObject.entityType);

                if (rs == null)
                {
                    return(false);
                }

                if (rs.isObligatory)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
Exemplo n.º 7
0
                public static bool Equals(RelationSide A, RelationSide B)
                {
                    bool AIsNull = (A == null);
                    bool BIsNull = (B == null);

                    if (AIsNull && BIsNull)
                    {
                        return(true);
                    }
                    if (AIsNull && !BIsNull)
                    {
                        return(false);
                    }
                    if (!AIsNull && BIsNull)
                    {
                        return(false);
                    }

                    return((A.targetClassName == B.targetClassName) && (A.fieldName == B.fieldName));
                }
Exemplo n.º 8
0
        private void MakeName(RelationSide side, bool warnDuplicateDetected = true)
        {
            bool isListName =
                (side == RelationSide.Right && cardinality == Cardinality.RM_1) ||
                (side == RelationSide.Left && cardinality == Cardinality.R1_M) ||
                cardinality == Cardinality.RM_M;
            string suffix     = isListName ? "List" : "";
            Entity nameSource = side == RelationSide.Left ? Entity2 : Entity;
            string root       = nameSource.Name;
            string newName    = String.Format("{0}{1}", root, suffix);
            bool   generated  = false;
            int    counter    = 1;

            while (Model.Relations.RelationExists(Entity, Entity2, newName, "*") ||
                   Model.Relations.RelationExists(Entity, Entity2, "*", newName))
            {
                generated = true;
                newName   = String.Format("{0}{1}{2}", root, counter++, suffix);
            }

            if (side == RelationSide.Left)
            {
                name = newName;
            }
            else
            {
                name2 = newName;
            }

            bool navigated = (side == RelationSide.Left && Navigate) || (side == RelationSide.Right && Navigate2);

            if (generated && navigated && warnDuplicateDetected)
            {
                Logger.Warning(WarningLevel.High,
                               "Relation name{0} \"{1}\" was generated for navigation. Specify name explicitely to avoid it. {2}",
                               SideToNameSuffix(side), newName, this);
            }
        }