XML Query API
Rapid Entity Framework query API is flexible enough to accommodate any query flavors, this is one good reason for developers to leverage this flexibilities to build a query or repository on top of the core API . The XML Query API allows you to query rapid entities by simply sending xml as query request and receiving the query results via the same means.

Sometimes in our architecture , we might want to send query results and/or entities as XML over the wire, Rapid gives you this features not only for free , but out of the box.
  1. XML Query Schema

Simple XML Architecture
xml-query-api.jpg

Sample XML Query request
<?xml version="1.0" encoding="utf-8" ?>
<Query xmlns="http://rql-rapid.org/RapidXmlSchema.xsd">
  <From Typeof="Employee" As="emp"/>
  <Where>
    <Expression Name="emp.Publisher"  Condition ="IsNotNull"/>
    <Expression Name="emp.Lname" Condition="Equals" Value="Muller"/>
  </Where>
  <OrderByAscending>
    <Expression Name="emp.Lname"/>
  </OrderByAscending>
  <Select>
    <Expression Name="emp.Publisher.Country"/>
    <Expression Name="emp.Hiredate"/>
    <Expression Name="emp.Lname"/>
  </Select>
</Query>

Execute Query using XMLQueryValidator class
Assuming we save the XML query above into an xml file called XMLFile1.xml Then we would use the following code snippet to execute the query.

XDocument aml = XDocument.Load( new StreamReader( @"XMLFile1.xml" ) );
XDocument doc = XmlQueryValidator.ExecuteQuery( aml );
Generated SQL
SELECT  
	[t1].[country] AS [R0],
	[t2].[hire_date] AS [R1],
	[t2].[lname] AS [R2] 
FROM  [employee] [t2]  , 
	( SELECT  
		[t0].[country] AS [country],
		[t0].[pub_id] AS [pub_id] 
	  FROM  [publishers] [t0] 
	) 
	t1  
WHERE  [t2].[pub_id]  IS NOT NULL 
AND  ( [t2].[lname]  =  @lnamet2_1_247b7 )   
AND  ( [t2].[pub_id]  =  [t1].[pub_id] )  
ORDER BY [t2].[lname] ASC

Query Result
<Query xmlns="http://rql-rapid.org/RapidXmlSchema.xsd">
  <row rowid="0">
    <column Value="USA" />
    <column Value="09/10/1993 00:00:00" />
    <column Value="Muller" />
  </row>
</Query>

Last edited Mar 3, 2010 at 8:25 AM by ahmedsalako, version 16

Comments

No comments yet.