Beispiel #1
0
        protected static string GetSelectFragment(OuterJoinableAssociation join, string entitySuffix, string collectionSuffix, OuterJoinableAssociation next = null)
        {
            switch (join.SelectMode)
            {
            case SelectMode.Undefined:
            case SelectMode.Fetch:
#pragma warning disable 618
                return(join.Joinable.SelectFragment(
                           next?.Joinable,
                           next?.RHSAlias,
                           join.RHSAlias,
                           entitySuffix,
                           collectionSuffix,
                           join.ShouldFetchCollectionPersister()));

#pragma warning restore 618

            case SelectMode.FetchLazyProperties:
                return(ReflectHelper.CastOrThrow <ISupportSelectModeJoinable>(join.Joinable, "fetch lazy propertie")
                       .SelectFragment(
                           next?.Joinable,
                           next?.RHSAlias,
                           join.RHSAlias,
                           entitySuffix,
                           collectionSuffix,
                           join.ShouldFetchCollectionPersister(),
                           true));

            case SelectMode.ChildFetch:
                return(ReflectHelper.CastOrThrow <ISupportSelectModeJoinable>(join.Joinable, "child fetch select mode").IdentifierSelectFragment(join.RHSAlias, entitySuffix));

            case SelectMode.JoinOnly:
                return(string.Empty);

            default:
                throw new ArgumentOutOfRangeException(nameof(join.SelectMode), $"{join.SelectMode} is unexpected.");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Generate a select list of columns containing all properties of the entity classes
        /// </summary>
        public string SelectString(IList <OuterJoinableAssociation> associations)
        {
            if (associations.Count == 0)
            {
                return(string.Empty);
            }
            else
            {
                SqlStringBuilder buf = new SqlStringBuilder(associations.Count * 3);

                int entityAliasCount     = 0;
                int collectionAliasCount = 0;

                for (int i = 0; i < associations.Count; i++)
                {
                    OuterJoinableAssociation join = associations[i];
                    OuterJoinableAssociation next = (i == associations.Count - 1) ? null : associations[i + 1];

                    IJoinable joinable     = join.Joinable;
                    string    entitySuffix = (suffixes == null || entityAliasCount >= suffixes.Length) ? null : suffixes[entityAliasCount];

                    string collectionSuffix = (collectionSuffixes == null || collectionAliasCount >= collectionSuffixes.Length)
                                                                                                                                                        ? null
                                                                                                                                                        : collectionSuffixes[collectionAliasCount];

                    string selectFragment =
                        GetSelectFragment(join, entitySuffix, collectionSuffix, next);

                    if (!string.IsNullOrWhiteSpace(selectFragment))
                    {
                        buf.Add(StringHelper.CommaSpace)
                        .Add(selectFragment);
                    }
                    if (joinable.ConsumesEntityAlias() && join.SelectMode != SelectMode.JoinOnly)
                    {
                        entityAliasCount++;
                    }

                    if (joinable.ConsumesCollectionAlias() && join.ShouldFetchCollectionPersister())
                    {
                        collectionAliasCount++;
                    }
                }

                return(buf.ToSqlString().ToString());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Get the order by string required for collection fetching
        /// </summary>
        protected SqlString OrderBy(IList <OuterJoinableAssociation> associations)
        {
            SqlStringBuilder buf = new SqlStringBuilder();

            OuterJoinableAssociation last = null;

            foreach (OuterJoinableAssociation oj in associations)
            {
                if (oj.ShouldFetchCollectionPersister())
                {
                    IQueryableCollection queryableCollection = (IQueryableCollection)oj.Joinable;
                    if (queryableCollection.HasOrdering)
                    {
                        string orderByString = queryableCollection.GetSQLOrderByString(oj.RHSAlias);
                        buf.Add(orderByString).Add(StringHelper.CommaSpace);
                    }
                }
                else if (!oj.IsCollection && last?.ShouldFetchCollectionPersister() == true)
                {
                    // it might still need to apply a collection ordering based on a
                    // many-to-many defined order-by...
                    IQueryableCollection queryableCollection = (IQueryableCollection)last.Joinable;
                    if (queryableCollection.IsManyToMany && last.IsManyToManyWith(oj))
                    {
                        if (queryableCollection.HasManyToManyOrdering)
                        {
                            string orderByString = queryableCollection.GetManyToManyOrderByString(oj.RHSAlias);
                            buf.Add(orderByString).Add(StringHelper.CommaSpace);
                        }
                    }
                }
                last = oj;
            }

            if (buf.Count > 0)
            {
                buf.RemoveAt(buf.Count - 1);
            }

            return(buf.ToSqlString());
        }