Linq is now finally integrated into Rapid Entity Framework. You can now use the EntityManager to query your entities as linq. Rapid Entity has three query flavours now.
  1. RQL Public : This query language is used by the client/users of Rapid Entity Framework. RQL (Rapid Query Language) Premier
  2. RQL Synatx Builder: This is used internally to translate RQL/Linq into database SQL queries. This is an abstraction layer of SQL queries which serve as a single query API to LINQ and RQL. Any new query language can be built ontop of this layer. *
  3. Linq Integration: Linq is now fully integrated into Rapid Entity Framework. At run time, the expression tree is traversed and the RQL Syntax Builder is used internally to construct the criterias that form the query. Here is a simple example of linq in REF to get you going :
  4. XML Query : You can send query xml and recieve XML as result using Rapid Entity Framework. For more on this, go to XML Query API

Download LINQ Samples

using(EntityManager manager = new EntityManager())
{
       manager.OpenDatabaseSession();
       var results = from customer in manager.AsQueryable<Customer>()
                          where customer.FirstName == "Ahmed" && customer.LastName.StartsWith("Sal")
                          select customer;
}

A more complex LINQ query
using ( EntityManager manager = new EntityManager( ) )
{
    manager.OpenDatabaseSession( );

    var products = ( from product in manager.AsQueryable<Product>( )
                     select new
                         {
                             Price = product.Price ,
                             Customer = from order in product.CustomerOrders
                                        select new
                                        {
                                            FirstName = order.Customer.FirstName
                                        }
                         }
                    );

    foreach ( var product in products )
    {
        Console.WriteLine( product.Price );
        Console.WriteLine( product.Customer.Select( c => c.FirstName ).FirstOrDefault( ) );
    }

More Samples

                var customers = ( from customer in manager.AsQueryable<Customer>( )
                                  select new
                                  {
                                      CompanyName = customer.CompanyName ,
                                      OrderCount = customer.Orders.Count
                                  } 
                                ).ToList( );

Download LINQ Examples here . The example makes use of the PUBS Database

Download

Last edited Apr 14, 2010 at 4:08 PM by ahmedsalako, version 23

Comments

No comments yet.