We have greatly improved the power of our DynamicQuery API, and there is still much more coming before our next official release goes into production. This is just a quick blog post to show some of the upcoming enhancements.
This query doesn’t really make sense, but we wanted to show you what will be possible in the next release.
EmployeesQuery q = new EmployeesQuery(); q.Select(q.LastName.Substring(2, 4).ToLower()); q.OrderBy(q.LastName.Substring(2, 4).ToLower().Descending); q.GroupBy(q.LastName.Substring(2, 4).ToLower()); EmployeesCollection coll = new EmployeesCollection(); if (coll.Load(q)) { string s = q.es.LastQuery; }
EmployeesQuery q = new EmployeesQuery(); q.Select(q.LastName.Substring(2, 4).ToLower()); q.OrderBy(q.LastName.Substring(2, 4).ToLower().Descending); q.GroupBy(q.LastName.Substring(2, 4).ToLower());
EmployeesCollection coll = new EmployeesCollection(); if (coll.Load(q)) { string s = q.es.LastQuery; }
The SQL Generated is as follows (and works)
SELECT SUBSTRING(LOWER([LastName]),2,4) AS 'LastName' FROM [Employees] GROUP BY SUBSTRING(LOWER([LastName]),2,4) ORDER BY SUBSTRING(LOWER([LastName]),2,4) DESC
In the current production release 2009.1.0209.0, you can only use a “Column Name” in the OrderBy and GroupBy statements. In the upcoming release, you will be able use full expressions, just as you can now do in the Select statement.
There may be times when you need to access some SQL feature that is not supported by our DynamicQuery API. But, now having used and fallen in love with DynamicQuery, the last thing you want to do is stop and go write a stored procedure or create a view. We have always supported the raw injection feature in our Select statement, but it will soon be available almost everywhere. The way it works is you pass in raw SQL in the form of a string surrounded by < > angle brackets. That indicates to the EntitySpaces dataproviders that you want the raw SQL passed directly to the database engine “as is”.
Here is an example query. You would never write a query like this in reality. EntitySpaces supports this simple query without having to use < > angle brackets. This is just to show all of the places that can accept the raw SQL injection technique:
EmployeesQuery q = new EmployeesQuery();q.Select("<FirstName>", q.HireDate);q.Where("<EmployeeID = 1>");q.GroupBy("<FirstName>", q.HireDate);q.OrderBy("<FirstName ASC>"); EmployeesCollection coll = new EmployeesCollection();if (coll.Load(q)){ string s = q.es.LastQuery;}
EmployeesQuery q = new EmployeesQuery();q.Select("<FirstName>", q.HireDate);q.Where("<EmployeeID = 1>");q.GroupBy("<FirstName>", q.HireDate);q.OrderBy("<FirstName ASC>");
EmployeesCollection coll = new EmployeesCollection();if (coll.Load(q)){ string s = q.es.LastQuery;}
SELECT FirstName,[HireDate] AS 'HireDate' FROM [Employees] WHERE (EmployeeID = 1) GROUP BY FirstName,[HireDate] ORDER BY FirstName ASC
Of course, you could easily write the above query without injection, but you get the idea. The escape hatch will be available to you almost everywhere ….
EmployeesQuery q = new EmployeesQuery();q.Select(q.FirstName);q.Where(q.EmployeeID == 1);q.OrderBy(q.FirstName.Ascending);q.GroupBy(q.FirstName, q.HireDate);
Using the raw SQL injection techniques above will allow you to invoke SQL functions that we don’t support, including database vender specific SQL, and so on. Hopefully, you will almost never have to resort to writing a custom load method to invoke a stored procedure or an entirely hand written SQL statement. Of course, you can use our native API everywhere and just inject the raw SQL on the GroupBy for instance. You can mix and match to get the desired SQL.
There’s much more to come in this release … Just last night we were serializing DynamicQuery’s from a Silverlight application and sending them to a WCF server to fetch the data… very slick. Watch for an upcoming blog post on our Silverlight demo very soon.
From Mobile Devices to large scale enterprise solutions in need of serious transaction support, EntitySpaces can meet your needs. Whether you’re writing an ASP.NET application with Medium Trust requirements, a Mono application, or a Windows.Forms application, the EntitySpaces architecture is there for you. EntitySpaces is provider independent, which means that you can run the same binary code against any of the supported databases. EntitySpaces is available in both C# and VB.NET. EntitySpaces uses no reflection, no XML files, and sports a tiny foot print of less than 200k. Pound for pound, EntitySpaces is one tough, dependable .NET architecture.
EntitySpaces LLCPersistence Layer and Business Objects for Microsoft .NEThttp://www.entityspaces.net
Page rendered at Tuesday, March 16, 2010 6:39:16 AM (Eastern Standard Time, UTC-05:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.