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


C# QueryTranslator.AddCollection方法代码示例

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


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

示例1: AddFromCollection

		/// <summary>
		/// 
		/// </summary>
		/// <param name="q"></param>
		/// <returns></returns>
		public string AddFromCollection(QueryTranslator q)
		{
			IType collectionElementType = PropertyType;

			if (collectionElementType == null)
			{
				throw new QueryException(
					string.Format("must specify 'elements' for collection valued property in from clause: {0}", path));
			}
			if (collectionElementType.IsEntityType)
			{
				// an association
				IQueryableCollection collectionPersister = q.GetCollectionPersister(collectionRole);
				IQueryable entityPersister = (IQueryable) collectionPersister.ElementPersister;
				string clazz = entityPersister.EntityName;

				string elementName;
				if (collectionPersister.IsOneToMany)
				{
					elementName = collectionName;
					// allow index() function
					q.DecoratePropertyMapping(elementName, collectionPersister);
				}
				else
				{
					// many to many
					q.AddCollection(collectionName, collectionRole);
					elementName = q.CreateNameFor(clazz);
					AddJoin(elementName, (IAssociationType) collectionElementType);
				}
				q.AddFrom(elementName, clazz, joinSequence);
				currentPropertyMapping = new CollectionPropertyMapping(collectionPersister);
				return elementName;
			}
			
			// collection of values
			q.AddFromCollection(collectionName, collectionRole, joinSequence);
			return collectionName;
		}
开发者ID:khaliyo,项目名称:Spring.net-NHibernate.net-Asp.net-MVC-DWZ-,代码行数:44,代码来源:PathExpressionParser.cs

示例2: Token


//.........这里部分代码省略.........
				}
			}
			else if (funcStack.HasFunctions)
			{
				bool constantToken = false;
				var expectedParen = parenCount + ((insideNew) ? -1 : 0);
				if (!readyForAliasOrExpression && expectedParen != funcStack.NestedFunctionCount)
				{
					throw new QueryException("'(' expected after HQL function in SELECT");
				}
				try
				{
					ParserHelper.Parse(funcStack.PathExpressionParser, q.Unalias(token), ParserHelper.PathSeparators, q);
				}
				catch (QueryException)
				{
					if (IsPathExpression(token))
						throw;
					// If isn't a path the token is added like part of function arguments
					constantToken = true;
				}

				if (token.StartsWith(ParserHelper.HqlVariablePrefix))
				{
					q.AddNamedParameter(token.Substring(1));
					q.AppendScalarSelectParameter();
				}
				else if (constantToken)
				{
					q.AppendScalarSelectToken(token);
				}
				else
				{
					if (funcStack.PathExpressionParser.IsCollectionValued)
					{
						q.AddCollection(
							funcStack.PathExpressionParser.CollectionName,
							funcStack.PathExpressionParser.CollectionRole);
					}
					q.AppendScalarSelectToken(funcStack.PathExpressionParser.WhereColumn);
					funcStack.PathExpressionParser.AddAssociation(q);
				}
				// after a function argument
				readyForAliasOrExpression = false;
			}
			else
			{
				if (!readyForAliasOrExpression)
				{
					throw new QueryException("',' expected in SELECT before:" + token);
				}

				try
				{
					//High probablly to find a valid pathExpression
					ParserHelper.Parse(pathExpressionParser, q.Unalias(token), ParserHelper.PathSeparators, q);
					if (pathExpressionParser.IsCollectionValued)
					{
						q.AddCollection(
							pathExpressionParser.CollectionName,
							pathExpressionParser.CollectionRole);
					}
					else if (pathExpressionParser.WhereColumnType.IsEntityType)
					{
						q.AddSelectClass(pathExpressionParser.SelectName);
					}
					q.AppendScalarSelectTokens(pathExpressionParser.WhereColumns);
					q.AddSelectScalar(pathExpressionParser.WhereColumnType);
					pathExpressionParser.AddAssociation(q);
				}
				catch (QueryException)
				{
					// Accept costants in SELECT: NH-280
					// TODO: Parse a costant expression like 5+3+8 (now is not supported in SELECT)
					if (IsStringCostant(token))
					{
						q.AppendScalarSelectToken(token);
						q.AddSelectScalar(NHibernateUtil.String);
					}
					else if (IsIntegerConstant(token))
					{
						q.AppendScalarSelectToken(token);
						q.AddSelectScalar(GetIntegerConstantType(token));
					}
					else if (IsFloatingPointConstant(token))
					{
						q.AppendScalarSelectToken(token);
						q.AddSelectScalar(GetFloatingPointConstantType());
					}
					else if (token.StartsWith(ParserHelper.HqlVariablePrefix))
					{
						q.AddNamedParameter(token.Substring(1));
						q.AppendScalarSelectParameter();
					}
					else
						throw;
				}
				readyForAliasOrExpression = false;
			}
		}
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:101,代码来源:SelectParser.cs

示例3: PrepareForIndex

		private void PrepareForIndex(QueryTranslator q)
		{
			IQueryableCollection collPersister = q.GetCollectionPersister(collectionRole);

			if (!collPersister.HasIndex)
			{
				throw new QueryException("unindexed collection before []");
			}
			string[] indexCols = collPersister.IndexColumnNames;
			if (indexCols.Length != 1)
			{
				throw new QueryException("composite-index appears in []: " + path);
			}

			JoinSequence fromJoins = new JoinSequence(q.Factory)
				.SetUseThetaStyle(useThetaStyleJoin)
				.SetRoot(collPersister, collectionName)
				.SetNext(joinSequence.Copy());

			if (!continuation)
			{
				AddJoin(collectionName, collPersister.CollectionType);
			}
			joinSequence.AddCondition(new SqlString(collectionName + '.' + indexCols[0] + " = "));

			CollectionElement elem = new CollectionElement();
			elem.ElementColumns = collPersister.GetElementColumnNames(collectionName);
			elem.Type = collPersister.ElementType;
			elem.IsOneToMany = collPersister.IsOneToMany;
			elem.Alias = collectionName;
			elem.JoinSequence = joinSequence;
			collectionElements.Add(elem); //addlast
			SetExpectingCollectionIndex();

			q.AddCollection(collectionName, collectionRole);
			q.AddJoin(collectionName, fromJoins);
		}
开发者ID:khaliyo,项目名称:Spring.net-NHibernate.net-Asp.net-MVC-DWZ-,代码行数:37,代码来源:PathExpressionParser.cs

示例4: Token


//.........这里部分代码省略.........
				if ("*".Equals(token) && !afterAggregatePath)
				{
					q.AddSelectScalar(GetFunction("count", q).ReturnType(NHibernateUtil.Int64, q.Factory));
				} //special case
				afterAggregatePath = false;
			}
			else if (GetFunction(lctoken, q) != null && token == q.Unalias(token))
			{
				// the name of an SQL function
				if (!ready)
				{
					throw new QueryException(", expected before aggregate function in SELECT: " + token);
				}
				aggregate = true;
				afterAggregatePath = false;
				aggregateAddSelectScalar = true;
				aggregateFuncTokenList.Insert(0, lctoken);
				ready = false;
				q.AppendScalarSelectToken(token);
				if (!AggregateHasArgs(lctoken, q))
				{
					q.AddSelectScalar(AggregateType(aggregateFuncTokenList, null, q));
					if (!AggregateFuncNoArgsHasParenthesis(lctoken, q))
					{
						aggregateFuncTokenList.RemoveAt(0);
						if (aggregateFuncTokenList.Count < 1)
						{
							aggregate = false;
							ready = false;
						}
						else
						{
							ready = true;
						}
					}
				}
			}
			else if (aggregate)
			{
				bool constantToken = false;
				if (!ready)
				{
					throw new QueryException("( expected after aggregate function in SELECT");
				}
				try
				{
					ParserHelper.Parse(aggregatePathExpressionParser, q.Unalias(token), ParserHelper.PathSeparators, q);
				}
				catch (QueryException)
				{
					constantToken = true;
				}
				afterAggregatePath = true;

				if (constantToken)
				{
					q.AppendScalarSelectToken(token);
				}
				else
				{
					if (aggregatePathExpressionParser.IsCollectionValued)
					{
						q.AddCollection(
							aggregatePathExpressionParser.CollectionName,
							aggregatePathExpressionParser.CollectionRole);
					}
					q.AppendScalarSelectToken(aggregatePathExpressionParser.WhereColumn);
					if (aggregateAddSelectScalar)
					{
						q.AddSelectScalar(AggregateType(aggregateFuncTokenList, aggregatePathExpressionParser.WhereColumnType, q));
						aggregateAddSelectScalar = false;
					}
					aggregatePathExpressionParser.AddAssociation(q);
				}
			}
			else
			{
				if (!ready)
				{
					throw new QueryException(", expected in SELECT");
				}

				ParserHelper.Parse(pathExpressionParser, q.Unalias(token), ParserHelper.PathSeparators, q);
				if (pathExpressionParser.IsCollectionValued)
				{
					q.AddCollection(
						pathExpressionParser.CollectionName,
						pathExpressionParser.CollectionRole);
				}
				else if (pathExpressionParser.WhereColumnType.IsEntityType)
				{
					q.AddSelectClass(pathExpressionParser.SelectName);
				}
				q.AppendScalarSelectTokens(pathExpressionParser.WhereColumns);
				q.AddSelectScalar(pathExpressionParser.WhereColumnType);
				pathExpressionParser.AddAssociation(q);

				ready = false;
			}
		}
开发者ID:Novthirteen,项目名称:sconit_timesseiko,代码行数:101,代码来源:SelectParser.cs


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