当前位置: 首页>>代码示例>>C#>>正文


C# QueryTranslator.AddSelectScalar方法代码示例

本文整理汇总了C#中NHibernate.Hql.Classic.QueryTranslator.AddSelectScalar方法的典型用法代码示例。如果您正苦于以下问题:C# QueryTranslator.AddSelectScalar方法的具体用法?C# QueryTranslator.AddSelectScalar怎么用?C# QueryTranslator.AddSelectScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NHibernate.Hql.Classic.QueryTranslator的用法示例。


在下文中一共展示了QueryTranslator.AddSelectScalar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Token

		public void Token(string token, QueryTranslator q)
		{
			SessionFactoryHelper helper = new SessionFactoryHelper(q.Factory);
			string lctoken = token.ToLowerInvariant();

			if (first)
			{
				first = false;
				if ("distinct".Equals(lctoken))
				{
					q.Distinct = true;
					return;
				}
				else if ("all".Equals(lctoken))
				{
					q.Distinct = false;
					return;
				}
			}

			if (afterNew)
			{
				afterNew = false;
				holderClass = helper.GetImportedClass(token);
				if (holderClass == null)
				{
					throw new QueryException("class not found: " + token);
				}
				q.HolderClass = holderClass;
				insideNew = true;
			}
			else if (token.Equals(StringHelper.Comma))
			{
				if (readyForAliasOrExpression)
				{
					throw new QueryException("alias or expression expected in SELECT");
				}
				q.AppendScalarSelectToken(StringHelper.CommaSpace);
				readyForAliasOrExpression = true;
			}
			else if ("new".Equals(lctoken))
			{
				afterNew = true;
				readyForAliasOrExpression = false;
			}
			else if (StringHelper.OpenParen.Equals(token))
			{
				parenCount++;
				if (!funcStack.HasFunctions && holderClass != null && !readyForAliasOrExpression)
				{
					//opening paren in new Foo ( ... )
					readyForAliasOrExpression = true;
				}
				else if (funcStack.HasFunctions)
				{
					q.AppendScalarSelectToken(token);
				}
				else
				{
					throw new QueryException("HQL function expected before '(' in SELECT clause.");
				}
				readyForAliasOrExpression = true;
			}
			else if (StringHelper.ClosedParen.Equals(token))
			{
				parenCount--;
				if (parenCount < 0)
				{
					throw new QueryException("'(' expected before ')' in SELECT clause.");
				}

				if (insideNew && !funcStack.HasFunctions && !readyForAliasOrExpression)
				{
					//if we are inside a new Result(), but not inside a nested function
					insideNew = false;
				}
				else if (funcStack.HasFunctions)
				{
					q.AppendScalarSelectToken(token);
					IType scalarType = funcStack.GetReturnType();
					funcStack.Pop();

					// Can't have an alias or expression right after the closing parenthesis of a function call.
					readyForAliasOrExpression = false;

					// if all functions were parsed add the type of the first function in stack
					if (!funcStack.HasFunctions)
						q.AddSelectScalar(scalarType);
				}
			}
			else if (IsHQLFunction(lctoken, q) && token == q.Unalias(token))
			{
				if (!readyForAliasOrExpression && !funcStack.HasFunctions)
				{
					// The syntax control inside a functions is delegated to the render
					throw new QueryException("',' expected before function in SELECT: " + token);
				}
				if (funcStack.HasFunctions && funcStack.FunctionGrammar.IsKnownArgument(lctoken))
				{
					// Some function, like extract, may have KnownArgument with the same name of another function
//.........这里部分代码省略.........
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:101,代码来源:SelectParser.cs

示例2: Token

		/// <summary>
		/// 
		/// </summary>
		/// <param name="token"></param>
		/// <param name="q"></param>
		public void Token(string token, QueryTranslator q)
		{
			string lctoken = token.ToLower(CultureInfo.InvariantCulture);

			if (first)
			{
				first = false;
				if (lctoken.Equals("distinct"))
				{
					q.Distinct = true;
					return;
				}
				else if (lctoken.Equals("all"))
				{
					q.Distinct = false;
					return;
				}
			}

			if (afterNew)
			{
				afterNew = false;
				holderClass = SessionFactoryHelper.GetImportedClass(q.Factory, token);
				if (holderClass == null)
				{
					throw new QueryException("class not found: " + token);
				}
				q.HolderClass = holderClass;
				insideNew = true;
			}
			else if (token.Equals(StringHelper.Comma))
			{
				if (ready)
				{
					throw new QueryException("alias or expression expected in SELECT");
				}
				q.AppendScalarSelectToken(StringHelper.CommaSpace);
				ready = true;
			}
			else if ("new".Equals(lctoken))
			{
				afterNew = true;
				ready = false;
			}
			else if (StringHelper.OpenParen.Equals(token))
			{
				if (!aggregate && holderClass != null && !ready)
				{
					//opening paren in new Foo ( ... )
					ready = true;
				}
				else if (aggregate)
				{
					q.AppendScalarSelectToken(token);
				}
				else
				{
					throw new QueryException("aggregate function expected before ( in SELECT");
				}
				ready = true;
			}
			else if (StringHelper.ClosedParen.Equals(token))
			{
				if (insideNew && !aggregate && !ready)
				{
					//if we are inside a new Result(), but not inside a nested function
					insideNew = false;
				}
				else if (aggregate && ready)
				{
					q.AppendScalarSelectToken(token);
					aggregateFuncTokenList.RemoveAt(0);
					if (aggregateFuncTokenList.Count < 1)
					{
						aggregate = false;
						ready = false;
					}
				}
				else
				{
					throw new QueryException("( expected before ) in select");
				}
			}
			else if (countArguments.Contains(lctoken))
			{
				if (!ready || !aggregate)
				{
					throw new QueryException(token + " only allowed inside aggregate function in SELECT");
				}
				q.AppendScalarSelectToken(token);
				if ("*".Equals(token) && !afterAggregatePath)
				{
					q.AddSelectScalar(GetFunction("count", q).ReturnType(NHibernateUtil.Int64, q.Factory));
				} //special case
				afterAggregatePath = false;
//.........这里部分代码省略.........
开发者ID:Novthirteen,项目名称:sconit_timesseiko,代码行数:101,代码来源:SelectParser.cs


注:本文中的NHibernate.Hql.Classic.QueryTranslator.AddSelectScalar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。