1. Select Whole Entity

using ( EntityManager manager = new EntityManager() )
{
    manager.OpenDatabaseSession();

    var t8 = manager.AsAlias<Employee>( );

    var employees = new From( typeof( Employee ) ).As( t8 )
                         .Where( t8.Hiredate ).Month( m => m.GreaterThan( 10 ) )
                         .SelectNew( ( ) => t8 ).Execute( );
}

//Generated SQL
SELECT  
       [t0].[fname],
       [t0].[minit],
       [t0].[lname],
       [t0].[job_lvl],
       [t0].[hire_date],
       [t0].[emp_id],
       [t0].[job_id],
       [t0].[pub_id]

FROM  [employee] [t0]
WHERE  DATEPART(MONTH, [t0].[hire_date])  >  @hire_datet0_0_97ddf

2. Select single Property

  var t6 = manager.AsAlias<Title>( );
  var results2 = new From( typeof( Title ) ).As( t6 )
                       .Where( t6.Price ).IsNotNull( )
                       .SelectNew( ( ) => t6.Pubdate ).Execute();

//Generated SQL
SELECT  [t0].[pubdate] AS [R0] FROM  [titles] [t0]
WHERE  [t0].[price]  IS NOT NULL

3. Select Multiple Properties (Using Anonymous)

var t1 = manager.AsAlias<Publisher>();
var results = new From( typeof( Publisher ) ).As( t1 )
                     .SelectNew
                        ( ( ) =>
                               new
                               {
                                  Name = t1.Pubname ,
                                  Country = t1.Country
                               }
                        ).Execute( );

//Generated SQL
 SELECT  [t0].[pub_name] AS [R0],
         [t0].[country] AS [R1]
FROM  [publishers] [t0]

4. Select Multiple Properties (Non Anonymous)

var t1 = manager.AsAlias<Publisher>();
var results = new From( typeof( Publisher ) ).As( t1 )
                    .SelectNew
                      ( ( ) =>
                         new Result
                             {
                               Name = t1.Pubname ,
                               Country = t1.Country ,
                               City = t1.City
                             }
                       ).Execute( );

//Generated SQL

 SELECT  [t0].[pub_name] AS [R0],
         [t0].[country] AS [R1],
         [t0].[city] AS [R2]
FROM  [publishers] [t0]


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

Comments

No comments yet.