Tuesday, November 20, 2007

Now that EntitySpaces 2007.1.1119.0 has been released we thought we would start a series of blog posts that highlights some of API enhancements. The most obvious place to begin is the Dynamic Query API as that is what many of our customers work in every day. We start off with some simple queries and work up to more complex queries.

Query - Simple select with where clause

Here is a simple query that brings back only the FirstName column for only those records that begin with the letter "M". Notice we use the % sign to indicate any characters after. You also use the % signs for all other supported databases. The EntitySpaces data providers will adjust accordingly for all other databases. Also, notice that we are using the built in query object on the collection itself. We recommend that you use this syntax always when there is no join involved.

EmployeesCollection coll = new EmployeesCollection ();
coll.Query.Select(coll.Query.FirstName);
coll.Query.Where(coll.Query.FirstName.Like("M%");
if(coll.Query.Load())
{
    // at least one record was loaded
}

The resulting SQL:

SELECT [FirstName]  FROM [Northwind].[dbo].[Employees] WHERE [FirstName] LIKE @FirstName1

Query - Arithmetic operators and complex where clause with AND/OR

This query shows off some of the natural language features of the EntitySpaces Dynamic Query API. Notice the use of the + operator to concatenate the FullName and LastName and providing the new derived column with an alias. Also notice the Where clause and it's use the | operator. You can use & for AND and | for OR and you can use ( ) for precedence.

EmployeesCollection coll = new EmployeesCollection ();
coll.Query.Select((coll.Query.LastName + "," + coll.Query.FirstName).As("FullName"));
coll.Query.Where(coll.Query.City == "Indianapolis" | coll.Query.Region == "Northeast");
if(coll.Query.Load())
{
    // at least one record was loaded
}

The resulting SQL:

SELECT ([LastName]+','+[FirstName]) AS 'FullName'  FROM [Northwind].[dbo].[Employees] WHERE ([City] = @City1 OR [Region] = @Region2)

Query - Aggregates with OrderBy and GroupBy

This query shows off some of the natural language features of the EntitySpaces Dynamic Query API. Notice the use of the + operator to concatenate the FullName and LastName and providing the new derived column with an alias. Also notice the Where clause and it's use the | operator. You can use & for AND and | for OR and you can use ( ) for precedence. Also, we had to use two calls to OrderBy because of the dynamic column created by the alias, however, you can pass multiple columns in like this -> coll.Query.OrderBy(coll.Query.ProductID.Descending, coll.Query.CategoryID.Ascending)

OrderDetailsCollection coll = new OrderDetailsCollection ();
coll.Query.Select
(
    coll.Query.ProductID,
    (coll.Query.Quantity * coll.Query.UnitPrice).Sum().As("TotalPrice")
);
coll.Query.GroupBy(coll.Query.ProductID);
coll.Query.OrderBy(coll.Query.ProductID.Ascending);
coll.Query.OrderBy("TotalPrice", esOrderByDirection.Ascending);
if(coll.Query.Load())
{
    // at least one record was loaded
}

The resulting SQL:

SELECT [ProductID],SUM(([Quantity]*[UnitPrice])) AS 'TotalPrice'  FROM [Northwind].[dbo].[Order Details] GROUP BY [ProductID] ORDER BY [ProductID] ASC,[TotalPrice] ASC

Query - Join Syntax

Notice the syntax here is a little different. When creating join based queries you do not use the embedded query object on the collection, you create your own and be sure to give it an alias. When you are not creating a join use the embedded query object as the examples above show. Also, in join scenarios you can select all from a particular column by passing the query into the select statement as follows -> Select(cust, order.OrderId) in this example the select will be Customer.*, Order.OrderId.

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); // Notice we load the query via the Collection.Load() method

The resulting SQL:

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

Miscellaneous Tips and Tricks

  • You can trick a query object and force it to load from a database view instead of the table as follows

query.es.QuerySource = "SomeView";

  • Top, CountAll, Distinct, PageNumber, PageSize, LastQuery are all available in the coll.query.es data member.

EntitySpaces

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 LLC
Persistence Layer and Business Objects for Microsoft .NET
http://www.entityspaces.net

posted on Tuesday, November 20, 2007 12:14:19 AM (Eastern Standard Time, UTC-05:00)  #   
 Sunday, November 18, 2007

I made a blog post a while ago in a thread entitled "Microsoft ruined data binding in ASP.NET 2.0 when they dropped component support from the design surface" and thought it worthy of a follow up.

ICustomTypeDescriptor

In order to allow strongly typed entities to tack on dynamic properties (extra columns brought back via a dynamic query) for data binding in ASP.NET data grid scenarios you must implement the ICustomTypeDescriptor interface. Since our latest release (v1119) supports joins it is now common to bring back extra columns for display purposes in EntitySpaces. Well, we implemented the ICustomTypeDescriptor interface on our esEntity class and it worked perfectly in ASP.NET, however, testing then showed it broke data binding in certain Windows.Forms scenarios. Why? There is a BUG in the Microsoft.NET Framework. It's not like bugs are not found in EntitySpaces of course, this is merely an explanation of how we have arrived to this point.

We have a few ways to work around the issue. One is to use our Collection.LowLevelBind() method and the other is adding properties to your entity (not very attractive). Our esDataSource control allows you to bring back extra columns and it binds just fine, there is a "LowLevelBind" method on the esDataSource for just this scenario. This only effects ASP.NET as Windows.Forms uses ITypedList which works like a champ (in hierarchical mode also).

HierarchicalDataSourceControl

The new HierarchicalDataSourceControl binding set of interfaces proved utterly incapable of displaying a hierarchical object model. We had it "kind of working" when we realized that this new binding model only supported a single parent/child relationship. This means it cannot display the EntitySpaces hierarchical object model. So, we withdrew the implementation of this feature. Scott Piegdon has a code sample on CodeProject, you can see his response to my "Ya, Butt" comment which validated my suspicions (nice article by the way).

Summary

Again, the new Microsoft ASP.NET data binding has proven to be flawed. It is next to impossible to support both ASP.NET and Windows.Forms binding with the same codebase due to a serious bug in the .NET Framework. Also, the HierarchicalDataSourceControl implementation suffers from a lack of foresight by its designers.

And finally (whining here) this all worked in the Microsoft .NET 1.x framework, see Part One as to how we got to where we are. The same ITypedList implementation worked for both ASP.NET and Windows.Forms. However, it was swapped out for some crazy DataSource model that is clearly geared for heavily reflected architectures. Well, EntitySpaces didn't take the bait. We are still 100% reflection free. We still run in "Medium Trust" and yes, we support the DataSource control but not the HierarchicalDataSourceControl. We have a plan to work around this issue entirely in a future release.

EntitySpaces

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 LLC
Persistence Layer and Business Objects for Microsoft .NET
http://www.entityspaces.net

posted on Sunday, November 18, 2007 9:24:47 PM (Eastern Standard Time, UTC-05:00)  #   

The official EntitySpaces 2007.1.1119 Release (Trial Version) is now available now on our home page. Sunday night we will post the Developer and Source downloads. The release notes can be found here. Please, if you find anything report it right away. We are very pleased with this release and we hope you will be too.  We recommend you uninstall your current trial before installing.

- The EntitySpaces Team 

posted on Sunday, November 18, 2007 12:00:57 AM (Eastern Standard Time, UTC-05:00)  #   
 Saturday, November 10, 2007

Our next beta will sport "pure" WCF client side proxies. These proxies allow the client side of a WCF conversation to seemlessly  communicate with your heavier server proxies without the need for EntitySpaces on the client side. Our new client side proxies are very lightweight, strongly typed, and match your server side. The first scenario below showing EntitySpaces on both sides of the conversation is of course still possible, however, we have added the "EntitySpaces on the Server Only Model" which we will discuss in further detail now.

For those interested in our new client side proxies there is a new template that you will need to run to create them. These generated proxies would be placed in a tiny class library and used by the client to communicate with your server.

Your client side proxies will look like this, first, the collection class.

Notice that the collection is a partial class. This will allow you to add functionality if needed. Also notice that there is no link to EntitySpaces whatsoever. You serialize from your Server Side Proxy and deserialize into your Client Side Proxies.  Now let's take a look at the entity class (which is also contained in the collection).

Again the single entity client side proxy has no link to EntitySpaces yet you can deserialize your heavier server side proxies into these tiny lightweight proxies on the client side. Notice the partial class definition as well. The row state is maintained for you as well. All you need to do is modify your data on the client side and ship it back to the server.

Here is a simulated converation between the server and client side proxies.

In the above sample we are serializing from the server proxy into a string which simulates your packet being sent over the wire to the client. Next we deserialize into our lightweight client proxy, change the employee's FirstName, and then ship it back over the wire to the server to be saved. The nice thing is that when you deserialize on your server you merely grab the true Employee business object from the proxy and save it, it's so easy.

EntitySpaces

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 LLC
Persistence Layer and Business Objects for Microsoft .NET
http://www.entityspaces.net

posted on Saturday, November 10, 2007 10:56:44 AM (Eastern Standard Time, UTC-05:00)  #   
 Sunday, November 04, 2007

The first official MyGeneration since it has gone open source on SourceForge.net under the BSD licensing model is coming soon. There are some very cool new features as well. First, and very importantly, you can now install the new MyGeneration side-by-side with the MyGeneration 1.2.0.7 release that is on Download.com. MyGeneration is still going strong with over 100,000 downloads on download.com and MyGeneration already ranks 172nd on SourceForge.net. Many have joined in on the project. MyGeneration is getting much more powerful, please help us keep this wonderful, totally free, code generation tool moving forward. Many have done so and we thank you. The next EntitySpaces beta we put out will support this version of MyGeneration also.

You will want to thank Justin Greenwood for this release, not to take away from the others who have also worked on this release, but I know Justin has put a lot of time in on this.



The current MyGeneration beta is 2007.11.03 1.3 Beta 7 and is pretty stable, and remember, you can install it side-by-side with your current install and not worry about messing up your current installation. Here are some new features listed below with more complete notes found HERE.

The user interface has been reworked, the DockPanel Suite has been upgraded, the default settings dialog is now an MDI window. You will notice that intellisense is being added, while not yet on par with the capabilities of Visual Studio there is some support for intellisense for C# and VB.NET templates now. There is a much improved error window with the ability to email errors to the developers working on MyGeneration. There is a powerful new PlugIn API that will even allow your PlugIn to operate as an MDI window within MyGeneration giving you full graphical control as well. Some of the new plug-ins are:

1) CodeSmith2MyGen converter

Converts CodeSmith templates to MyGeneration Templates (only partially).

2) MyGenXsd3b

MyGenXsd3b providerplugin for MyGeneration

MyGenXsd3b is a provider plugin that allows MyGeneration to

  • Use a XML model file instead of an online database
  • To create model file from an existing database
  • To create model file from an existing model file

Benefits:

  • You can use MyGeneration even if the database is not available.
  • You can share database models with other developpers.
  • You can connect MyGeneration with the xml input or output of other modeling tools.
    • UML/XMI ( Xsd3bImportFromUml )
    • XSD ( XSDFile, Dot Net Typed Dataset )
    • XDM entity relationship model file ( MogwaiERDesignerModelXdm )
    • You can integrate MyGeneration with new XML sources using xsl-files ( XSD3bXSLT ) and share these with other users .
  • MyGenXsd3b-s native xml fileformat XSD3bFile
    • is mutch more intuitive than XSDFile
    • can be viewed with any xsl-capable htmlbrowser

MyGenXsd3b is autamtically installed with MyGeneration Version 1.3 or newer ( MyGenXsd3bInstallation )

Implementation Details

MyGenXsd3b

  • is implemented as a MyGeneration-Plugin dll MyMeta.Plugins.Xsd3b.dll.
  • is linked against the MyGeneration-Api dll MyMeta.dll
  • is linked against the Xsd3bEngine Dl3bak.Xsd3b.dll that handles all the xmlstuff.

The Xsd3bEngine has Xsd3bPlugin-dlls for specific fileformats

  • UML/XMI ( Xsd3bImportFromUml ) Dl3bak.Xsd3b.Uml14Xmi12Import.dll
  • XSD ( XSDFile, Dot Net Typed Dataset ) Dl3bak.Xsd3b.Xsd.dll
  • Convert from and to foreign XML via XSL ( XSD3bXSLT ) Dl3bak.Xsd3b.Xslt.dll

The xsl engine XSD3bXSLT uses xsl files in the folder Templates/xsd3b/

  • Mogwai ERDesignerModel.xdm.xsd3b.xsl to convert Mogwai ERDesignerModel from xdm to xsd3b ( MogwaiERDesignerModelXdm )
  • DatabaseReport.xsd3b.htm.xsl to create a DatabaseReport from xsd3b to htm format

3) SQL Tool

Allows you to execute SQL queires in a window against your database, can be very handy.

I have only touched on the new features, there is so much more that could be said ...


MyGeneration - The Free Code Generator / OR Mapping Tool the competition doesn't want you to know about


Download your copy of MyGeneration 1.3 now ==> DOWNLOAD  and don't forget the install the two plugins as well (seperate installs)

 

kick it on DotNetKicks.com
posted on Sunday, November 04, 2007 11:40:06 AM (Eastern Standard Time, UTC-05:00)  #