I just had to make another post, this is so much fun. Writing queries in our enhanced dynamic query language is totally awesome, and so powerful. I'm writing some unit tests to go into our massive NUnit test suite and just had to post these ...
public void JoinWithArithmeticExpressionOrderByCalulatedColumn(){ // Notice I create a calulated columns based on the TotalSales, then Order by it descending CustomerQuery cust = new CustomerQuery("c"); OrderQuery order = new OrderQuery("o"); OrderItemQuery item = new OrderItemQuery("oi"); cust.Select(cust.CustomerName, (item.Quantity * item.UnitPrice).Sum().As("TotalSales")); cust.InnerJoin(order).On(order.CustID == cust.CustomerID); cust.InnerJoin(item).On(item.OrderID == order.OrderID); cust.GroupBy(cust.CustomerName); cust.OrderBy("TotalSales", esOrderByDirection.Descending); CustomerCollection coll = new CustomerCollection(); coll.Load(cust);}
public void JoinWithArithmeticExpressionOrderByCalulatedColumn(){ // Notice I create a calulated columns based on the TotalSales, then Order by it descending CustomerQuery cust = new CustomerQuery("c"); OrderQuery order = new OrderQuery("o"); OrderItemQuery item = new OrderItemQuery("oi");
cust.Select(cust.CustomerName, (item.Quantity * item.UnitPrice).Sum().As("TotalSales")); cust.InnerJoin(order).On(order.CustID == cust.CustomerID); cust.InnerJoin(item).On(item.OrderID == order.OrderID); cust.GroupBy(cust.CustomerName); cust.OrderBy("TotalSales", esOrderByDirection.Descending);
CustomerCollection coll = new CustomerCollection(); coll.Load(cust);}
The SQL produced:
SELECT c.[CustomerName],SUM(oi.[Quantity]) AS 'TotalSales' FROM [ForeignKeyTest].[dbo].[Customer] c JOIN [ForeignKeyTest].[dbo].[Order] o ON (o.[CustID] = c.[CustomerID]) JOIN [ForeignKeyTest].[dbo].[OrderItem] oi ON (oi.[OrderID] = o.[OrderID]) GROUP BY c.[CustomerName] ORDER BY TotalSales DESC
The result set is CustomerName / TotalSales sorted in decending order by TotalSales ...
Another query I wrote merely concatenated the Employee FirstName and LastName columns, and upper cased them.
public void ArithmeticConcatenationNoJoinWithSubOperator(){ EmployeeCollection coll = new EmployeeCollection(); EmployeeQuery q = coll.Query; q.Select( (q.LastName + "," + q.FirstName).ToUpper().As("FullName") ); q.OrderBy(q.LastName.Ascending); coll.Query.Load();}
public void ArithmeticConcatenationNoJoinWithSubOperator(){ EmployeeCollection coll = new EmployeeCollection(); EmployeeQuery q = coll.Query;
q.Select( (q.LastName + "," + q.FirstName).ToUpper().As("FullName") ); q.OrderBy(q.LastName.Ascending);
coll.Query.Load();}
I've seen many of our competitors query languages, I think by far EntitySpaces has the cleanest, most straight-forward syntax, by light years in most cases. We've got some really cool stuff coming, hang on ...
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, 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.
The EntitySpaces Team--
EntitySpaces LLCPersistence Layer and Business Objects for Microsoft .NEThttp://www.entityspaces.net
Page rendered at Thursday, March 18, 2010 3:41:13 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.