本文整理汇总了C#中NHibernate.Engine.QueryParameters类的典型用法代码示例。如果您正苦于以下问题:C# QueryParameters类的具体用法?C# QueryParameters怎么用?C# QueryParameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueryParameters类属于NHibernate.Engine命名空间,在下文中一共展示了QueryParameters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SubselectOneToManyLoader
public SubselectOneToManyLoader(IQueryableCollection persister, SqlString subquery, ICollection<EntityKey> entityKeys,
QueryParameters queryParameters,
ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters)
: base(persister, BatchSizeForSubselectFetching, factory, enabledFilters)
{
keys = new object[entityKeys.Count];
int i = 0;
foreach (EntityKey entityKey in entityKeys)
{
keys[i++] = entityKey.Identifier;
}
// NH Different behavior: to deal with positionslParameter+NamedParameter+ParameterOfFilters
namedParameters = new Dictionary<string, TypedValue>(queryParameters.NamedParameters);
parametersSpecifications = queryParameters.ProcessedSqlParameters.ToList();
var processedRowSelection = queryParameters.ProcessedRowSelection;
SqlString finalSubquery = subquery;
if (queryParameters.ProcessedRowSelection != null && !SubselectClauseExtractor.HasOrderBy(queryParameters.ProcessedSql))
{
// when the original query has an "ORDER BY" we can't re-apply the pagination.
// This is a simplification, we should actually check which is the "ORDER BY" clause because when the "ORDER BY" is just for the PK we can re-apply "ORDER BY" and pagination.
finalSubquery = GetSubSelectWithLimits(subquery, parametersSpecifications, processedRowSelection, namedParameters);
}
InitializeFromWalker(persister, finalSubquery, BatchSizeForSubselectFetching, enabledFilters, factory);
types = queryParameters.PositionalParameterTypes;
values = queryParameters.PositionalParameterValues;
}
示例2: SqlCommandImpl
public SqlCommandImpl(SqlString query, ICollection<IParameterSpecification> specifications, QueryParameters queryParameters, ISessionFactoryImplementor factory)
{
this.query = query;
this.specifications = specifications;
this.queryParameters = queryParameters;
this.factory = factory;
}
示例3: ValidateFailureDifferentLengths
public void ValidateFailureDifferentLengths()
{
QueryParameters qp = new QueryParameters(
new IType[] { NHibernateUtil.String },
new object[] { });
qp.ValidateParameters();
}
示例4: ValidateOk
public void ValidateOk()
{
QueryParameters qp = new QueryParameters(
new IType[] {NHibernateUtil.String},
new object[] {"string"});
qp.ValidateParameters();
}
示例5: ValidateFailureDifferentLengths
public void ValidateFailureDifferentLengths()
{
QueryParameters qp = new QueryParameters(
new IType[] {NHibernateUtil.String},
new object[] {});
Assert.Throws<QueryException>(() => qp.ValidateParameters());
}
示例6: ResetEffectiveExpectedType
public static void ResetEffectiveExpectedType(this IEnumerable<IParameterSpecification> parameterSpecs, QueryParameters queryParameters)
{
// TODO: remove this method when we can infer the type during the parse
foreach (var parameterSpecification in parameterSpecs.OfType<IExplicitParameterSpecification>())
{
parameterSpecification.SetEffectiveType(queryParameters);
}
}
示例7: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
ISessionFactoryImplementor factory = criteriaQuery.Factory;
var innerQuery = new CriteriaQueryTranslator(
factory,
criteriaImpl, //implicit polymorphism not supported (would need a union)
criteriaImpl.EntityOrClassName,
criteriaQuery.GenerateSQLAlias(),
criteriaQuery);
types = innerQuery.HasProjection ? innerQuery.ProjectedTypes : null;
if (innerQuery.HasProjection == false)
{
throw new QueryException("Cannot use subqueries on a criteria without a projection.");
}
IOuterJoinLoadable persister = (IOuterJoinLoadable) factory.GetEntityPersister(criteriaImpl.EntityOrClassName);
//patch to generate joins on subqueries
//stolen from CriteriaLoader
CriteriaJoinWalker walker =
new CriteriaJoinWalker(persister, innerQuery, factory, criteriaImpl, criteriaImpl.EntityOrClassName, enabledFilters);
parameters = innerQuery.GetQueryParameters(); // parameters can be inferred only after initialize the walker
SqlString sql = walker.SqlString;
if (criteriaImpl.FirstResult != 0 || criteriaImpl.MaxResults != RowSelection.NoValue)
{
int? offset = Loader.Loader.GetOffsetUsingDialect(parameters.RowSelection, factory.Dialect);
int? limit = Loader.Loader.GetLimitUsingDialect(parameters.RowSelection, factory.Dialect);
Parameter offsetParameter = offset.HasValue ? innerQuery.CreateSkipParameter(offset.Value) : null;
Parameter limitParameter = limit.HasValue ? innerQuery.CreateTakeParameter(limit.Value) : null;
sql = factory.Dialect.GetLimitString(sql, offset, limit, offsetParameter, limitParameter);
}
SqlStringBuilder buf = new SqlStringBuilder().Add(ToLeftSqlString(criteria, criteriaQuery));
if (op != null)
{
buf.Add(" ").Add(op).Add(" ");
}
if (quantifier != null && prefixOp)
{
buf.Add(quantifier).Add(" ");
}
buf.Add("(").Add(sql).Add(")");
if (quantifier != null && prefixOp == false)
{
buf.Add(" ").Add(quantifier);
}
return buf.ToSqlString();
}
示例8: Bind
public void Bind(IDbCommand command, IList<Parameter> multiSqlQueryParametersList, int singleSqlParametersOffset, IList<Parameter> sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session)
{
IType type = keyType;
object value = queryParameters.PositionalParameterValues[queryParameterPosition];
string backTrackId = GetIdsForBackTrack(session.Factory).First(); // just the first because IType suppose the oders in certain sequence
int position = sqlQueryParametersList.GetEffectiveParameterLocations(backTrackId).Single(); // an HQL positional parameter can't appear more than once
type.NullSafeSet(command, value, position + singleSqlParametersOffset, session);
}
示例9: BindLimitParametersLastIfNeccesary
protected virtual int BindLimitParametersLastIfNeccesary(IDbCommand command, QueryParameters parameter, int colIndex)
{
RowSelection selection = parameter.RowSelection;
if (Loader.Loader.UseLimit(selection, dialect) && !dialect.BindLimitParametersFirst)
{
return Loader.Loader.BindLimitParameters(command, colIndex, selection, session);
}
return 0;
}
示例10: Bind
public override void Bind(IDbCommand command, IList<Parameter> multiSqlQueryParametersList, int singleSqlParametersOffset, IList<Parameter> sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session)
{
TypedValue typedValue = queryParameters.NamedParameters[name];
string backTrackId = GetIdsForBackTrack(session.Factory).First(); // just the first because IType suppose the oders in certain sequence
foreach (int position in sqlQueryParametersList.GetEffectiveParameterLocations(backTrackId))
{
ExpectedType.NullSafeSet(command, GetPagingValue(typedValue.Value, session.Factory.Dialect, queryParameters), position + singleSqlParametersOffset, session);
}
}
示例11: Bind
public void Bind(IDbCommand command, IList<Parameter> multiSqlQueryParametersList, int singleSqlParametersOffset, IList<Parameter> sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session)
{
TypedValue typedValue = queryParameters.NamedParameters[name];
string backTrackId = GetIdsForBackTrack(session.Factory).First();
foreach (int position in sqlQueryParametersList.GetEffectiveParameterLocations(backTrackId))
{
ExpectedType.NullSafeSet(command, typedValue.Value, position + singleSqlParametersOffset, session);
}
}
示例12: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
InitializeInnerQueryAndParameters(criteriaQuery);
if (innerQuery.HasProjection == false)
{
throw new QueryException("Cannot use subqueries on a criteria without a projection.");
}
ISessionFactoryImplementor factory = criteriaQuery.Factory;
IOuterJoinLoadable persister = (IOuterJoinLoadable)factory.GetEntityPersister(criteriaImpl.EntityOrClassName);
//patch to generate joins on subqueries
//stolen from CriteriaLoader
CriteriaJoinWalker walker =
new CriteriaJoinWalker(persister, innerQuery, factory, criteriaImpl, criteriaImpl.EntityOrClassName, enabledFilters);
parameters = innerQuery.GetQueryParameters(); // parameters can be inferred only after initialize the walker
SqlString sql = walker.SqlString;
if (criteriaImpl.FirstResult != 0 || criteriaImpl.MaxResults != RowSelection.NoValue)
{
int? offset = Loader.Loader.GetOffsetUsingDialect(parameters.RowSelection, factory.Dialect);
int? limit = Loader.Loader.GetLimitUsingDialect(parameters.RowSelection, factory.Dialect);
Parameter offsetParameter = offset.HasValue ? innerQuery.CreateSkipParameter(offset.Value) : null;
Parameter limitParameter = limit.HasValue ? innerQuery.CreateTakeParameter(limit.Value) : null;
sql = factory.Dialect.GetLimitString(sql, offset, limit, offsetParameter, limitParameter);
}
// during CriteriaImpl.Clone we are doing a shallow copy of each criterion.
// this is not a problem for common criterion but not for SubqueryExpression because here we are holding the state of inner CriteriaTraslator (ICriteriaQuery).
// After execution (ToSqlString) we have to clean the internal state because the next execution may be performed in a different tree reusing the same istance of SubqueryExpression.
innerQuery = null;
SqlStringBuilder buf = new SqlStringBuilder().Add(ToLeftSqlString(criteria, criteriaQuery));
if (op != null)
{
buf.Add(" ").Add(op).Add(" ");
}
if (quantifier != null && prefixOp)
{
buf.Add(quantifier).Add(" ");
}
buf.Add("(").Add(sql).Add(")");
if (quantifier != null && prefixOp == false)
{
buf.Add(" ").Add(quantifier);
}
return buf.ToSqlString();
}
示例13: Bind
public int Bind(
IDbCommand statement,
QueryParameters qp,
ISessionImplementor session,
int position)
{
object value = qp.PositionalParameterValues[_queryParameterPosition];
_keyType.NullSafeSet(statement, value, position, session);
return _keyType.GetColumnSpan(session.Factory);
}
示例14: Bind
public int Bind(IDbCommand statement, QueryParameters qp, ISessionImplementor session, int position)
{
int bindCount = 0;
foreach (IParameterSpecification spec in _paramSpecs)
{
bindCount += spec.Bind(statement, qp, session, position + bindCount);
}
return bindCount;
}
示例15: SubselectFetch
public SubselectFetch(string alias, ILoadable loadable, QueryParameters queryParameters,
ISet<EntityKey> resultingEntityKeys)
{
this.resultingEntityKeys = resultingEntityKeys;
this.queryParameters = queryParameters;
this.loadable = loadable;
this.alias = alias;
queryString = queryParameters.ProcessedSql.GetSubselectString();
}