Sunday, February 25, 2007

Another area of enhancement is complete, and that is our improvements to the EntitySpaces Dynamic Query API. We took some steps not covered in this blog post to hide extraneous items from the intellisense when building Dynamic Query's via intellisense. We have also opened the door to all kinds of SubOperators, some simple samples are shown below, of course these work on all of the EntitySpaces data providers as well. It is our hope that during our 1.6 beta our users will suggest more SubOperators, and as long as they apply across most databases there's a good chance they will make the release.

So here's the Sneak Peak ...


Notice the ToLower() SubOperator and the As() aliasing mechanism. These are both new to the 1.6 DynamicQuery Mechanism.

Employees emp = new Employees();
emp.Query.Select(emp.Query.LastName.ToLower().As("LastNameLower"));
emp.Query.Where(emp.Query.EmployeeID == 1);
emp.Query.Load();

Generates ...

SELECT LOWER([LastName]) AS 'LastNameLower' FROM [Employees] WHERE ([EmployeeID] = @EmployeeID1)



Notice the LTrim and Substring SubOperators as well as the As aliasing mechanism

Employees emp = new Employees();
emp.Query.Select(emp.Query.LastName.LTrim().Substring(0,1).As("FirstInitial"));
emp.Query.Where(emp.Query.EmployeeID == 1);
emp.Query.Load();

Generates ...

SELECT LTRIM(SUBSTRING([LastName],0,1)) AS 'FirstInitial' FROM [Employees] WHERE ([EmployeeID] = @EmployeeID1)



Finally, the Aggregates underwent a breaking change, it will be very easy to upgrade these and we felt it important to have our Aggregates conform with the rest of the syntax. We apologize for the breaking change but felt it important to make this change now. We feel that when you look at the two syntax's shown below you will agree the 1.6 syntax is superior and really shines with intellisense.

1.5.3 Syntax
emp.Query.Select(emp.Query.LastName.Count("TheCount", true));

1.6.0 Syntax
emp.Query.Select(emp.Query.LastName.Count().Distinct().As("TheCount"));



The SubOperators that will be available in the 1.6 March 4th beta are as follows:

  • ToUpper
  • ToLower
  • LTrim
  • RTrim
  • Trim
  • Substring

There are many more that can be implemented, the architecture is now in place to support them and the syntax nests properly as you can see in the Substring example above. Something we've been thinking about that won't make our 1.6 Release but will find it's way onto an upcoming Roadmap is SubSelects. We already support the IN in the where clause of course. We're not sure on the syntax but perhaps something like this:

Future Roadmap ....

Customers cust = new Customers();
Employees emp = new Employees();

emp.Query.Select(emp.Query.EmployeeID, emp.Query.FirstName);
emp.Query.Where(emp.Query.EmployeeID.In
(
     emp.Query.SubSelect(cust.Query.Location == "Indianapolis");
)
emp.Query.Load();


The EntitySpaces Team
--
EntitySpaces LLC
Persistence Layer and Business Objects for Microsoft .NET 2.0
http://www.entityspaces.net/