1. Special Functions

1. Count All Entities
using ( EntityManager manager = new EntityManager() )
{
    manager.OpenDatabaseSession();

    int authorCount = manager.Count<Author>( );
}

2. Limiting Results (Range Operation)
Get results from 0 to 10
using ( EntityManager manager = new EntityManager() )
{
    manager.OpenDatabaseSession();   
   var limitedAuthors = manager.Limit<Author>( 0 , 10 ).ToList( );
}

//Bonus Hints. You can also limit with RQL
var t0 = manager.AsAlias<Employee>();
var limit = new From( typeof( Employee ) ).As( t0 )
                   .SelectNew( ( ) =>
                        new
                        {
                              Name = t0.Fname ,
                              EmpId = t0.Empid
                         }
                         ).Limit( 1 , 13 );

2. Get All Lazily (Cursor based get all)
The lazy Get All keeps the datareader open, and it reads to next row when you iterate it. Behind the sceen the IDataReader.Read method is called per each iterations. This concept is the laziest approach to iterating large data. Each Read is on demand.
using ( EntityManager manager = new EntityManager() )
{
    manager.OpenDatabaseSession();
    var lazyAuthors = manager.GetAllLazily<Author>( );

    foreach ( var a in lazyAuthors )
   {
      Console.WriteLine( a.Aufname + a.Aulname );
   }
}

2. Transforming entity to XML (Entity Serialization)
using ( EntityManager manager = new EntityManager() )
{
    manager.OpenDatabaseSession();
    var t0 = manager.AsAlias<Employee>();
    var first = new From( typeof( Employee ) ).As( t0 )
                     .SelectNew( ( ) => t0 ).First( );

    XmlDocument xml = manager.GetXMLFromEntity<Employee>( first );
}
//Genetrated XML
<?xml version="1.0" encoding="utf-8" ?> 
- <Employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Fname>Paolo</Fname> 
  <Minit>M</Minit> 
  <Lname>Accorti</Lname> 
  <Joblvl>35</Joblvl> 
  <Hiredate>1992-08-27T00:00:00</Hiredate> 
  <Empid>PMA42628M</Empid> 
- <Job>
  <Jobdesc>Sales Representative</Jobdesc> 
  <Minlvl>25</Minlvl> 
  <Maxlvl>100</Maxlvl> 
  <Jobid>13</Jobid> 
  </Job>
- <Publisher>
  <Pubname>Binnet & Hardley</Pubname> 
  <City>Washington</City> 
  <State>DC</State> 
  <Country>USA</Country> 
  <Pubid>0877</Pubid> 
  </Publisher>
  </Employee>

3. Transforming the xml back into Entity (Reverse Engineering the XML)
using ( EntityManager manager = new EntityManager() )
{
    manager.OpenDatabaseSession();
    var t0 = manager.AsAlias<Employee>();
    var first = new From( typeof( Employee ) ).As( t0 )
                     .SelectNew( ( ) => t0 ).First( );

    XmlDocument xml = manager.GetXMLFromEntity<Employee>( first );
    Employee xmlEmployee = manager.GetEntityFromXml<Employee>( xml );
}

Last edited Feb 4, 2010 at 1:15 PM by ahmedsalako, version 10

Comments

No comments yet.