Пример #1
0
        private static SqlString[] GetColumnNamesUsingProjection(
            IProjection projection, ICriteriaQuery criteriaQuery, ICriteria criteria)
        {
            var sqlString = projection.ToSqlString(criteria, criteriaQuery.GetIndexForAlias(), criteriaQuery);

            return(new SqlString[] { SqlStringHelper.RemoveAsAliasesFromSql(sqlString) });
        }
        private void SetFields(ICriteriaQuery criteriaQuery)
        {
            //Persister is required, so let's use it as "initialized marker"
            if (Persister != null)
            {
                return;
            }

            if (!(criteriaQuery is ISupportEntityProjectionCriteriaQuery entityProjectionQuery))
            {
                throw new ArgumentException(
                          $"Projecting to entities requires a '{criteriaQuery.GetType().FullName}' type to implement " +
                          $"{nameof(ISupportEntityProjectionCriteriaQuery)} interface.",
                          nameof(criteriaQuery));
            }

            var criteria = entityProjectionQuery.RootCriteria;

            if (!Lazy)
            {
                entityProjectionQuery.RegisterEntityProjection(this);
            }

            if (_entityType == null)
            {
                _entityType = criteria.GetRootEntityTypeIfAvailable();
            }

            if (_entityAlias == null)
            {
                _entityAlias = criteria.Alias;
            }

            Persister = criteriaQuery.Factory.GetEntityPersister(_entityType.FullName) as IQueryable;
            if (Persister == null)
            {
                throw new HibernateException($"Projecting to entities requires a '{typeof(IQueryable).FullName}' persister, '{_entityType.FullName}' does not have one.");
            }

            ICriteria subcriteria = criteria.GetCriteriaByAlias(_entityAlias);

            if (subcriteria == null)
            {
                throw new HibernateException($"Criteria\\QueryOver alias '{_entityAlias}' for entity projection is not found.");
            }

            TableAlias = criteriaQuery.GetSQLAlias(
                subcriteria,
                Persister.IdentifierPropertyName ?? string.Empty);

            ColumnAliasSuffix = BasicLoader.GenerateSuffix(criteriaQuery.GetIndexForAlias());

            _identifierColumnAliases = Persister.GetIdentifierAliases(ColumnAliasSuffix);

            _types = new IType[] { TypeFactory.ManyToOne(Persister.EntityName, true) };
        }
Пример #3
0
		internal static SqlString[] GetColumnNamesUsingProjection(IProjection projection, ICriteriaQuery criteriaQuery, ICriteria criteria,
																	 IDictionary<string, IFilter> enabledFilters)
		{
			SqlString sqlString = projection.ToSqlString(criteria, 
				criteriaQuery.GetIndexForAlias(),
				criteriaQuery, 
				enabledFilters);
			return new SqlString[]
				{
					StringHelper.RemoveAsAliasesFromSql(sqlString)
				};
		}
Пример #4
0
        internal static SqlString[] GetColumnNamesUsingProjection(IProjection projection, ICriteriaQuery criteriaQuery, ICriteria criteria,
                                                                  IDictionary <string, IFilter> enabledFilters)
        {
            SqlString sqlString = projection.ToSqlString(criteria,
                                                         criteriaQuery.GetIndexForAlias(),
                                                         criteriaQuery,
                                                         enabledFilters);

            return(new SqlString[]
            {
                StringHelper.RemoveAsAliasesFromSql(sqlString)
            });
        }
Пример #5
0
        internal static SqlString[] GetColumnNamesUsingProjection(IProjection projection, ICriteriaQuery criteriaQuery, ICriteria criteria)
        {
            if (projection is IPropertyProjection propertyProjection)
            {
                return(GetColumnNamesUsingPropertyName(criteriaQuery, criteria, propertyProjection.PropertyName));
            }

            SqlString sqlString = projection.ToSqlString(criteria,
                                                         criteriaQuery.GetIndexForAlias(),
                                                         criteriaQuery);

            return(new SqlString[]
            {
                SqlStringHelper.RemoveAsAliasesFromSql(sqlString)
            });
        }
 public static SqlString GetColumnName(this IProjection projection, ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
 {
     return SqlStringHelper.RemoveAsAliasesFromSql(
         projection.ToSqlString(criteria, criteriaQuery.GetIndexForAlias(), criteriaQuery, enabledFilters)
     );
 }
Пример #7
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
        {
            var namesUsingProjections = _projections.Select(p => SqlStringHelper.RemoveAsAliasesFromSql(p.ToSqlString(criteria, criteriaQuery.GetIndexForAlias(), criteriaQuery, enabledFilters))).ToArray();

            var parameter = criteriaQuery.NewQueryParameter(_typedValue).Single();

            var sqlStringBuilder = new SqlStringBuilder();

            sqlStringBuilder.Add(_functionName);
            sqlStringBuilder.Add("(");
            sqlStringBuilder.Add("(");
            for (var i = 0; i < namesUsingProjections.Length; i++)
            {
                sqlStringBuilder.Add(namesUsingProjections[0]);
                if (i != namesUsingProjections.Length - 1)
                {
                    sqlStringBuilder.Add(",");
                }
            }

            sqlStringBuilder.Add(")");

            sqlStringBuilder.Add(",");
            sqlStringBuilder.Add(parameter);

            if (_language.HasValue)
            {
                sqlStringBuilder.Add(string.Format(",language {0}", _language));
            }

            sqlStringBuilder.Add(")");

            return(sqlStringBuilder.ToSqlString());
        }
 public static SqlString GetColumnName(this IProjection projection, ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
 {
     return(SqlStringHelper.RemoveAsAliasesFromSql(
                projection.ToSqlString(criteria, criteriaQuery.GetIndexForAlias(), criteriaQuery, enabledFilters)
                ));
 }