コード例 #1
0
		/// <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;
				System.Type clazz = entityPersister.MappedClass;

				string[] collectionElementColumns = CurrentColumns();

				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 );
					string[] keyColumnNames = entityPersister.IdentifierColumnNames;
					join.AddJoin( entityPersister.TableName, elementName, collectionElementColumns, keyColumnNames, joinType );
				}
				q.AddFrom( elementName, clazz, join );
				currentPropertyMapping = new CollectionPropertyMapping( collectionPersister );
				return elementName;
			}
			else
			{
				// collection of values
				q.AddFromCollection( collectionName, collectionRole, join );
				return collectionName;
			}
		}
コード例 #2
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="q"></param>
		/// <returns></returns>
		public string AddFromAssociation( QueryTranslator q )
		{
			if ( IsCollectionValued )
			{
				return AddFromCollection( q );
			}
			else
			{
				q.AddFrom( currentName, join );
				return currentName;
			}
		}