예제 #1
0
        private static void AppendHqlClauses(QueryBuildingContext queryContext, StringBuilder sb)
        {
            sb.Append(" from ");
            sb.Append(queryContext.RootClass.FullName);
            sb.Append(" ent");

            // add joins
            foreach (var join in queryContext.Joins)
            {
                sb.Append($" {GetJoinTypeString(join.JoinType)} join {join.Reference} {join.Alias}");
                if (!string.IsNullOrWhiteSpace(join.Condition))
                {
                    sb.Append(" on ");
                    sb.Append(join.Condition);
                }
            }

            if (queryContext.FilterCriteria.FilterClauses.Count > 0)
            {
                sb.Append(" where ");
                bool hasClause = false;
                foreach (var clause in queryContext.FilterCriteria.FilterClauses)
                {
                    if (hasClause)
                    {
                        sb.Append(" and ");
                    }

                    sb.Append("(");
                    sb.Append(clause);
                    sb.Append(")");
                    hasClause = true;
                }
            }
        }
예제 #2
0
        public static IQuery CreateQuery(this ISession session, QueryBuildingContext queryContext)
        {
            var sb = new StringBuilder();

            sb.Append("select ent ");

            AppendHqlClauses(queryContext, sb);

            if (!string.IsNullOrEmpty(queryContext.OrderBy))
            {
                sb.Append(" order by ");
                sb.Append(queryContext.OrderBy.Replace("ascending", "asc").Replace("descending", "desc"));
            }

            var q = session.CreateQuery(sb.ToString());

            TransferHqlParameters(q, queryContext.FilterCriteria);

            return(q);
        }
예제 #3
0
        public static IQuery CreateQueryCount(this ISession session, System.Type entityType, QueryBuildingContext queryContext)
        {
            var sb = new StringBuilder();

            sb.Append("select count(*) ");

            AppendHqlClauses(queryContext, sb);

            var q = session.CreateQuery(sb.ToString());

            TransferHqlParameters(q, queryContext.FilterCriteria);

            return(q);
        }