This section describes the use of the GroupBy RQL method for grouping query projections.

1. Group by one property
var t1 = manager.AsAlias<Publisher>();
var grouped = new From( typeof( Publisher ) ).As( t1 )
                  .GroupBy( t1.City )
                  .SelectNew( ( ) => t1.City ).Execute( );

//Generated Sql
SELECT  [t0].[city] AS [R0] FROM  [publishers] [t0]
GROUP BY [t0].[city]


2. Group by multiple properties
var t1 = manager.AsAlias<Publisher>();
var grouped = new From( typeof( Publisher ) ).As( t1 )
                  .GroupBy( t1.City , t1.Country )
                  .SelectNew( ( ) => t1.City ).Execute( );

//Generated Sql
SELECT  [t0].[city] AS [R0] 
FROM  [publishers] [t0]  
GROUP BY [t0].[city],[t0].[country]

3. Complex Group by using Path Expression ()
var t9 = manager.AsAlias<Employee>( );
var complex = new From( typeof( Employee ) ).As( t9 )
                     .Where( t9.Publisher.City ).Length( m => m.NotEqualsTo( 3 ) )
                     .GroupBy( t9.Publisher.City , t9.Publisher.Country )
                     .SelectNew( ( ) => t9.Publisher.City ).Execute( );

//Generated Sql
 SELECT  
        [t1].[city] AS [R0] 
FROM  [employee] [t2]  , ( SELECT  
                                 [t0].[city] AS [city],
                                 [t0].[country] AS [country],
                                 [t0].[pub_id] AS [pub_id] 
                           FROM  [publishers] [t0]  
                           WHERE  LEN([t0].[city])  <>  @cityt0_0_e7f37 
                         ) t1  
WHERE  [t2].[pub_id]  =  [t1].[pub_id]  
GROUP BY [t1].[city],[t1].[country]

Last edited Feb 3, 2010 at 7:44 PM by ahmedsalako, version 3

Comments

No comments yet.