Sunday, May 04, 2008

EntitySpaces and Silverlight Demo

Part 1: Propagating EntitySpaces Data

kick it on DotNetKicks.com


Jon_Davis 
Written by Jon Davis
http://www.jondavis.net/


 

Introduction

I was asked to see how easy it would be to get EntitySpaces objects to work inside Silverlight, and to demonstrate my findings. This was a curiously interesting notion, since many have pondered whether Silverlight is a valuable runtime environment for LOB (line-of-business) applications. There are a number of reasons why Silverlight, at least in its Version2 flavor, would be very ideal for building client/server applications:

· Silverlight 2 comes with pre-built user controls ideal for business environments, such as the basic Textbox and more advanced data grid with editable cells

· Silverlight 2's user controls support two-way data binding, so that synchronization can be performed easily in either direction

· Silverlight 2's runtime is fast and fluid, using retained graphics vector-based rendering rather than redraw-at-invalidate "lazy" rendering. This results in a very responsive, clean, and professional user experience.

· XAML takes lessons learned with ASP.NET with the separation of design from programming. Properly implemented, a Silverlight application can be completely re-skinned, with its layout completely reorganized, without touching any of the user interface programming code.

· Silverlight 2 ships with built-in support for the language of your choice of: C#, VB.NET, IronRuby, IronPython, or JScript.NET. The .NET Framework itself inside of Silverlight is stripped down, but the core CLR is complete, and the target deployment environment does NOT need the .NET Framework installed with it.

· Silverlight 2 runs not only on the Windows platform and on Internet Explorer, but it also runs happily on the Macintosh and in other browsers such as Firefox and Safari. This means that Silverlight is not just Microsoft's answer to Flash for its vector graphics, it's also Microsoft's decade-long-awaited answer to Java applets, "Write once, run anywhere." An investment in Silverlight on Windows is automatically a free, bonus investment in the Mac and Firefox runtime environments.

· Silverlight 2 is also capable of communicating at runtime with web services over HTTP, making synchronization a natural programming experience without "hacking".

So here I began. My first thought was to take the EntitySpaces generated objects and put them in a shared library, then reference them in my Silverlight application. This turned out not to work as I hoped, for a few important reasons worth mentioning:

· Silverlight 2 can only reference assemblies (DLLs) that had been compiled against Silverlight's custom CLR. It cannot reference assemblies that were compiled against the normal .NET Framework (or against Mono).This is actually an opportunity for EntitySpaces, at least in its current form, because ES is built around code generation, so theoretically you could get the generated code to target Silverlight. Or so I thought, until I found...

· Silverlight 2 only "speaks" HTTP. It doesn't "speak" T-SQL, so you cannot use an ADO.NET connection, for example. There is no System.Data namespace, no ADO.NET support. While this seemed bizarre and even annoying at first, eventually I began to understand, besides for obvious security reasons, why System.Data was not present in Silverlight 2 in the current beta form: CRUD is CRUD, it doesn't matter if it's happening over ADO.NET on a SQL connection or over HTTP, as long as the job gets done.

Now I was beginning to procrastinate, because I made too many dumb assumptions. "So I guess I have to use System.Net.WebClient", I thought, "to make a manual connection to a web server, invoke a REST query I have to manually implement on the server, and then manually bring it back, parse it out, and in the end enjoy no benefit to using EntitySpaces at all?" When I finally sat down and researched what I needed to do, my jaw dropped. It’s nothing like that. In fact, it's almost silly how simple this is. The answer to the problem of the need for easy business object data synchronization lies in a wonderfully consistent new approach provisioned by Microsoft called WCF, or Windows Communications Foundation, now implemented at a basic level in Silverlight.

WCF support on Silverlight is limited to basicHttpBinding (SOAP 1.1). But that binding should suffice for most business scenarios.

The power of WCF is actually somewhat less about the underlying technology than it is about the code generation tools built into Visual Studio for building out the necessary client proxy stubs from defined interfaces at design-time. EntitySpaces' built-in WCF took me there 75% of the way, but the Silverlight SDK closed the gap very quickly by allowing me to reference my WCF service in just a couple clicks.

There was no coding of System.Net.WebClient. No manual conversion of XML to C# objects. Just beautiful EntitySpaces proxy stubs that enabled me to gather rich business object data from a server and perform quick and easy data binding against Silverlight with minimal effort.

So in this first part, I'll describe the first "baby step" of getting Silverlight to interoperate with a WCF service in order to pass valuable EntitySpaces objects into Silverlight with very little effort. Following that, in the next part I'll describe a simple scenario of fetching filtered data based on a WCF callback parameter that then takes advantage of EntitySpaces query filtering on the server, again with only a few more lines of code. Finally, if I have time, I'll continue to research and then demonstrate how to take advantage of the new client-side query support that is already available in ES 2008's latest build, adding even more flexibility to the programming user experience.

 

Run the Demo Here  ==> http://developer.entityspaces.net/ES2008/Demos/Silverlight/PartOne

Download the Source Here ==> http://www.developer.entityspaces.net/downloads/EntitySpacesSilverlightDemo.zip 


Setup

These are the prerequisites you need to walk through this demo:

· Visual Studio 2008

· EntitySpaces 2007

· Microsoft Silverlight Tools Beta 1 for Visual Studio 2008

· Northwind database
 

image

Figure 1 - Download the Silverlight tools for Visual Studio

 

Setting Up the Project and Generating Northwind Business Objects

If you’re not already familiar with EntitySpaces, we need to walk through some initial code generation so that we have some business objects to begin with.

Since nearly everything we’re doing is going to be done inside of Visual Studio, let’s start off by creating a new solution.

clip_image002[19]

Figure 2 - Start up Visual Studio and start by creating a new Project 
 

clip_image002[17]

Figure 3 - Create a Silverlight Application using .NET Framework 3.5 
 

clip_image002[1]

Figure 4 - When you create a Silverlight Application, Visual Studio prompts you to ask whether you want to create a new web to the solution or if you just want a local HTML test page. Choose to add a new Web. 
 

In my opinion, the data objects that get passed around in an application should exist in their own class library and then referenced into the application that uses them.

clip_image002[21] 

Figure 5 - Add a new project to the solution ... 

 

clip_image002[25]

Figure 6 - .. and choose Class Library as the project type. You can delete the resulting Class1 file. 

I’m going to use MyGeneration 1.3 for this demonstration. After preparing Northwind for SQL Server, I can then fire up MyGeneration.

clip_image014

Figure 7 - Open the template browser 

clip_image002[61]

Figure 8 - Expand EntitySpaces, then C#, then right-click Generated Classes Master (C#), and choose Execute. 

clip_image018

Figure 9 - I have a Visual Studio class library project set up, waiting for new code to be added to the physical directory so that I can add the files to the project after they are generated. 

clip_image020

Figure 10 - I'd like to give the Namespace a similar name as the database: NorthwindData  

clip_image022

Figure 11 - You can pick and choose your tables -- we'll use Products and Categories -- but might as well select them all. 

clip_image024

Figure 12 - On the third tab, we want to enable the WCF proxies, as highlighted in the image.  

clip_image026

Figure 13 - Click the OK button at the bottom to generate the objects  

clip_image002[27]

Figure 14 - After a moment, you may receive a confirmation message. If not, no worries, as long as your error log window isn’t filled up.  

Now I can close MyGeneration and go back to Visual Studio.

clip_image002[29]

My NorthwindData project doesn’t have anything in it yet, let’s add the newly generated files.

clip_image002[11]

Figure 15 - Click the "Show All Files" toolbar button in the Solution Explorer window.  

clip_image002[31]

Figure 16 - Now we can see our generated files. Right-click on the folder and choose "Include In Project".  

Before we can call this class library “ready”, we need to remember to reference the EntitySpaces dependency assemblies.

clip_image002[33]

clip_image002[35]

Figure 17 - You need EntitySpaces.Core and EntitySpaces.Interfaces .. 

clip_image002[37]

Figure 18 - .. as well as System.Runtime.Serialization and System.ServiceModel for WCF proxy support. 

Finally, we should also add the same references to the Silverlight_Web project, as well as EntitySpaces.Loader, EntitySpaces.LoaderMT, EntitySpaces.SqlClientProvider, EntitySpaces.Web, and EntitySpaces.Web.Design.

You will also need to add updates to your web.config for EntitySpaces to be able to read from (and later write to) the Northwind database. Here’s what I have ..

<configuration>
   <configSections>
      <sectionGroup name="EntitySpaces" type="EntitySpaces.Interfaces.esConfigSettings, EntitySpaces.Core">
      <section name="connectionInfo" type="EntitySpaces.Interfaces.esConfigSettings, EntitySpaces.Interfaces"
          allowLocation="true" allowDefinition="Everywhere" restartOnExternalChanges="true"/>
</sectionGroup>
...

...
</system.webServer>

<EntitySpaces>
    <connectionInfo default="SQL">
      <connections>
         <add name="SQL" providerMetadataKey="esDefault" sqlAccessType="DynamicSQL" provider="EntitySpaces.SqlClientProvider"
              providerClass="DataProvider"
              connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;User Instance=True" databaseVersion="2005"/>
      </connections>
   </connectionInfo>
</EntitySpaces>

<runtime>
...


Discovering the Silverlight Tools

Before you got this far, you should have discovered that when you added the Silverlight Application, the Page.xaml file loaded right up to be edited. It might have looked like this:

clip_image042

Figure 19 - The XAML Editor view for a Silverlight Application 

This is a design canvas for a Silverlight application layout. Silverlight works like ASP.NET in that the design and the programming code are isolated from each other. There is a “code-behind” file, or a similar principle, just as with an .aspx file.

In the design (XAML) editor, there are two views on a split pane.

One view is the XAML text editor. Think of it as an HTML editor in a split pane view, such as in Microsoft Expression Web or in Dreamweaver. The only big difference here is that XAML isn’t HTML, obviously, and in fact XAML is much stricter and less forgiving of errors than HTML ever was. Even so, its power becomes evident when elements can be added to a view with minimal markup.

clip_image002[39]

Figure 20 - The XAML text editor pane.  

The other view is the Design view. Currently (at the time of this demo, the Silverlight Tools was only in Beta 1), this only works as a preview in Visual Studio. You can drag items from the toolbar to your layout, but only into the XAML text editor, not to the Design view. This isn’t the case if you have access to Blend 2.5, which at the time of this demo is currently in public Alpha (Technology Preview) and was not used for this demo at all. The design view does have some advantages, though. It provides a quick visual preview of the XAML text, and if you need to nitpick you can zoom in or out.

clip_image002[41]

Figure 21 - The Design pane.  

So let’s start adding some XAML and some logic to get, say, a data grid populated with the entire contents of the Northwind “Products” table, as provided by the EntitySpaces business objects we generated earlier.

Personally I don’t care for fixed dimensions before we even begin let’s just delete the Width and Height attributes on the <UserControl> XML node. This will make Silverlight fill the screen or else collapse to the largest object.

Next I want to add a data grid.

clip_image002[47]

Figure 22 - Drag a DataGrid control to the <Grid> content. 

I’ll add the attribute x:Name=”ESGrid”, which is the ID of the control on the page. The attribute AutogenerateColumns=”True” does what it suggests; when data is bound to the grid, the columns are automatically generated. (Without this setting, the grid would come up blank because I am not providing layout information for the columns.)

<Grid x:Name="LayoutRoot" Background="White">
    <my:DataGrid x:Name="ESGrid" AutoGenerateColumns="True"></my:DataGrid>
</Grid>

The next thing we should do is insert a “Please Wait” text block so that as we download the Products list. This is just for effect so that the user isn’t staring at a blank DataGrid or a blank screen before the data shows up. To make this effective, we should also hide the DataGrid until the data is ready.

<Grid x:Name="LayoutRoot" Background="White">
    <TextBlock Text="Please Wait .." x:Name="WaitText" VerticalAlignment="Center" HorizontalAlignment="Center" />
    <my:DataGrid x:Name="ESGrid" AutoGenerateColumns="True" Visibility="Collapsed" />
</Grid>

Now all our Silverlight app wants is some data. But before we can populate the DataGrid, we have to expose the data. So now we turn to our Silverlight_Web project.

Exposing the Data via A WCF Service

Open up the Property Pages for the Web project.

clip_image002[49]

The first thing that should come up is a list of References. Add a reference to the Northwind project
 

image

clip_image054

With Northwind added, we can now add a WCF service. Right-click on the Silverlight_Web project again and choose Add New Item…
 

clip_image056

.. and then choose WCF Service. We’ll name it “Northwind.svc”.
 

clip_image058

This generates four things:

  • An interface file defining the interface INorthwind
  • A Service (Northwind.svc) file that only acts as a stub for the code-behind C# file
  • A service implementation file (Northwind.svc.cs or App_Code/Northwind.cs) where the service code is actually going to be written, and finally
  • A set of entries in web.config that define

    • Your site’s serviceModel configuration settings such as the EndPoint configuration
    • Bindings to the Northwind service

In the Northwind service implementation, you’ll see a bogus DoWork method stub defined and exposed, like so:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

// NOTE: If you change the class name "Northwind" here, you must also update the reference to
// "Northwind" in Web.config.

public class Northwind : INorthwind
{
    public void DoWork()
    {

    }
}

You can toss this out but before you do you need to go and modify INorthwind.

Notice that INorthwind attributes itself with the ServiceContractAttribute. This identifies the interface as a WCF service interface definition. Exposed methods are attributed with OperationContractAttribute.

[ServiceContract]
public interface INorthwind
{
    [OperationContract]
    void DoWork();
}

Before we can see the Northwind project’s stuff in Intellisense, we need to build both it and the Silverlight_Web project. Right-click on the Silverlight_Web project, choose Build Web Site, and the Northwind project will build first because it is a dependency. (This is also a good time to check for errors.)

Now let’s add some code.

In INorthwind, replace “DoWork()” with “GetProducts()”, and change “void” to “NorthwindData.ProductsCollectionProxyStub”. Then go back to the service implementation file and replace “DoWork()” with “GetProducts()” again and “void” to “NorthwindData.ProductsCollectionProxyStub”.

Next, we can give the method stub some functionality.

public NorthwindData.ProductsCollectionProxyStub GetProducts()
{
    NorthwindData.ProductsCollection products = new NorthwindData.ProductsCollection();
    products.LoadAll();

    NorthwindData.ProductsCollectionProxyStub proxy = new NorthwindData.ProductsCollectionProxyStub(products);
    return proxy;
}

This will fetch all products, wrap them in a WCF-ready proxy, and spit back the proxy.

Now let’s make sure that our WCF service is functioning. Hit the Debug button in Visual Studio (while the Silverlight_Web project is selected) and when the web page comes up, navigate to Northwind.svc. You may get a prompt asking if you want to enable debugging, just say yes.

clip_image060

clip_image062

clip_image002[51]

If you can see the “Northwind Service” page, indicating “You have created a service,” you’re almost ready to start binding your service to Silverlight.

Stop the debugger before continuing.

 

Initializing EntitySpaces

Before this service will successfully work with EntitySpaces at runtime, the EntitySpaces runtime needs to be initialized to point to a database.

Right-click on the Silverlight_Web project node in Solution Explorer and choose “Add New Item...”, then select “Global Application Class” (name it the default, Global.asax). When it opens up, add the following code in Application_Start():

protected void Application_Start(object sender, EventArgs e)
{
    EntitySpaces.Interfaces.esProviderFactory.Factory = new EntitySpaces.LoaderMT.esDataProviderFactory();
}


Binding the WCF Service to Silverlight

Silverlight “speaks” WCF, but only using basicHttpBinding (SOAP 1.1). We need to update the endpoint configuration on the service so that it uses basicHttpBinding rather than the default wsHttpBinding.

Open web.config in Silverlight_Web and change wsHttpBinding to basicHttpBinding.

<system.serviceModel>
<behaviors>
    ...
</behaviors>
<services>
    <service behaviorConfiguration="NorthwindBehavior" name="Northwind">
    <endpoint address="" binding="basicHttpBinding" contract="INorthwind">
    ...

We also need to create a temporary lock on the port that our development web server (Cassini) is using. When Web projects are created within Visual Studio, a small web server loads up in the background, with a visible icon in the Windows Notification Area (or “system tray”), and the port that it uses is random. If we lock it, though, we can force Silverlight’s WCF bindings to always point to the correct web address when it calls back to the web server. This is only for debugging purposes; when deploying to production, a URL will be used literally, on port 80, as with http://www.mydomain.com/myService

To lock the web server port so that we can get a fixed reference on Silverlight, click on the Silverlight_Web project node in the Solution Explorer tree and disable the “Use dynamic ports” option.

clip_image066

Now it’s time to bind your WCF service to Silverlight. Right-click on the Silverlight project node in the Solution Explorer and choose “Add Service Reference ...”

clip_image002[53]

Then select “Discover >” and choose “Services in Solution”. The Silverlight_Web project is displayed. Expand it until you see the Northwind service, then expand that until you see the INorthwind service contract. Select the INorthwind service contract, and set the Namespace to “NorthwindClient”.
 

clip_image002[55]

Once you click on “OK”, the required assemblies for WCF support, all pre-compiled against the Silverlight runtime, are brought into Silverlight automatically.

clip_image002[57]

Great, I have my bindings. Now it’s time to populate my grid.

If you expand the Page.xaml node in the Solution Explorer, you should see the Page’s “code-behind”-ish file. Open that up and see what’s inside.

// using stuff ;
namespace EntitySpacesSilverlightDemo_Silverlight
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
        }
    }
}

So we already have a constructor here where we can fire off an invocation of the WCF service. Note: All System.Net.WebClient and WCF client calls are asynchronous, so you must plan for this ahead of time whenever programming callbacks with Silverlight.

After adding “using NorthwindClient;” to the top of the file, here’s my code for within the “class Page” block:

NorthwindClient.NorthwindClient ESNorthwind;

public Page()
{
    InitializeComponent();
    ESNorthwind = new NorthwindClient.NorthwindClient();
    ESNorthwind.GetProductsCompleted += new EventHandler<NorthwindClient.GetProductsCompletedEventArgs>(NorthwindClient_GetProductsCompleted);
    LoadAllProducts();
}

private void LoadAllProducts()
{
    WaitText.Visibility = Visibility.Visible;
    ESNorthwind.GetProductsAsync();
}

void NorthwindClient_GetProductsCompleted(object sender, NorthwindClient.GetProductsCompletedEventArgs e)
{
    WaitText.Visibility = Visibility.Collapsed;
    NorthwindClient.ProductsCollection pc = e.Result;
    ESGrid.ItemsSource = pc.Collection;
    ESGrid.Visibility = Visibility.Visible;
}

Hit F5 and run, and you should see something like this:

clip_image002[59]

This is what we were designing for. We have a data-bound DataGrid, where the data derives from the same EntitySpaces business objects I perhaps already invested in elsewhere on my site or in my application, and despite a learning curve for basic configuration for WCF interop, there was actually very little code that was written by hand.


Deployment to IIS

We’re not quite done yet. Now we have to look at deployment to a production server.

Silverlight’s binding to the services is hard-coded to the URL http://localhost:11434/Northwind.svc. Silverlight is then compiled and bundled directly into the web project that hosts the WCF service. We now have a chicken-or-egg situation; both projects depend on the other. Further, EntitySpaces is hosting this demo on a shared web host that uses IIS 7 which enables WCF services natively, but WCF on IIS 7 doesn’t support HTTP endpoints through web.config without a custom service factory.

Here’s a run-down on how we got this running at: http://developer.entityspaces.net/ES2008/Demos/Silverlight/PartOne/

  1. Upload the web project files to the web server via FTP and make sure that the directory paths correctly reflect the desired URLs.
  2. In Visual Studio, with the Solution still open, choose File -> Add -> Existing Web Site..., then select FTP on the left and fill out the necessary FTP information (hostname, username, password, directory).
    Be sure to enter the exact FTP directory path to the root of the web project.
  3. We now have two copies of the same web project loaded in our solution, the local copy and the FTP-based copy. Now we need to make some configuration changes in the FTP-based copy of the project in our solution.
    • Re-link the Silverlight project. Right-click on the Project node in the Solution Explorer, choose Properties Pages, and select Silverlight Links. (If anything there, remove it now so it is empty.) Click “Add...”, ensure that your Silverlight project is available in the drop-down list for “Project to link”, and keep the Destination folder set to “/”. Click Add and then click OK. You may get some warnings that the file(s) already exist, go ahead and choose to overwrite.
    • Restore the database connection. In web.config, change the connection string at configuration/EntitySpaces/connectionInfo/connections to point to a working instance of Northwind on SQL Server on the web host.
    • Add a Northwind service factory to the project. Open App_Code/Northwind.cs and make the following changes:

      // append to the "using" declarations at the top
      using System.ServiceModel.Activation;
      using System.Configuration;

      // append inside of namespace but before or after the Northwind class block
      public class NorthwindServiceHostFactory : ServiceHostFactory
      {
          protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
          {
              // Specify the exact URL of your web service
              Uri webServiceAddress = new Uri(ConfigurationManager.AppSettings["ServiceUri_Northwind"]);
              NorthwindServiceHost webServiceHost = new NorthwindServiceHost(serviceType, webServiceAddress);
              return webServiceHost;
          }
      }

      public class NorthwindServiceHost : ServiceHost
      {
          public NorthwindServiceHost(Type serviceType, params Uri[] baseAddresses)
              : base(serviceType, baseAddresses)
          { }

          protected override void ApplyConfiguration()
          {
              base.ApplyConfiguration();
          }
      }

    • Find the <appSettings> node of web.config (which might be collapsed as <appSettings/>, just change it to <appSettings><appSettings>) and add the following setting inside of it:

      <add key="ServiceUri_Northwind" value="http://developer.entityspaces.net/ES2008/Demos/Silverlight/PartOne/EntitySpacesSilverlightDemo_Silverlight_Web/Northwind.svc"/>
    • In web.config, under configuration/system.serviceModel/behaviors/serviceBehaviors, add:

      <behavior name="NorthwindFactoryBehavior" >
          <serviceMetadata httpGetEnabled="true" />
      </behavior>

    • Finally, under configuration/system.serviceModel/services, change

        <service behaviorConfiguration="NorthwindBehavior"  name="Northwind">

      .. to ..

        <service behaviorConfiguration="NorthwindFactoryBehavior" name="Northwind">

      .. and although I don’t think it’s used anyway with our factory, you might want to go ahead and change the <dns>localhost</dns> entry down in there to <dns>yourhost.com</dns>.

    • Build the solution. If build succeeds, ...
    • In the Silverlight project, expand the Service References node in the Solution Explorer and remove the NorthwindClient node by right-clicking it and choosing Delete. Then right-click on Service References and choose Add Service Reference. Click on Discover and choose Services in Solution. Select the FTP-based project. You may be asked to refine the URL, you will need to modify the default value to correctly reflect the accurate URL path to the Northwind.svc file on the live server.

    If you receive an error, open up a web browser and navigate directly to the URL of the Northwind.svc file. If it fails to show up, try to use the error message (Google is your friend) to drill down the problem. It may relate to something overlooked in the steps I described.

    1. Now right-click on the Silverlight project node in the Solution Explorer and build the project again.
    2. Finally, right-click on the web project node in the Solution Explorer and build the project again. This will pull the revised compiled Silverlight project into the hosted site.

    If you made it this far, all the hard stuff is over!! From here on out, it’s easy, blissful C# coding with EntitySpaces and a few XAML tweaks, no more configuration hassles.

    In Part 2 of this tutorial / demo, I’ll make the app a little bit more interactive, adding filters and the ability to make a few changes to the data. (It will be comparatively short compared to this part.) But now that you know how to link up ES objects to Silverlight over WCF, have fun and be safe!!



    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, 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.

    The EntitySpaces Team
    --

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

    posted on Sunday, May 04, 2008 7:59:06 PM (Eastern Standard Time, UTC-05:00)  #   
     Friday, May 02, 2008

     

    I Just Executed a Killer EntitySpaces 2008 DynamicQuery ...

    posted on Friday, May 02, 2008 8:37:40 PM (Eastern Standard Time, UTC-05:00)  #   
     Sunday, April 27, 2008
    kick it on DotNetKicks.com

    imageThe EntitySpaces 2008 Beta II is now available. The version number is 2008.0.0427.0 and is available for download now on our home page. You should uninstall any prior ES2008 alpha or beta that you may have installed. You can run ES2007 and ES2008 side-by-side. Do not install ES2008 over the top of ES2007. EntitySpaces 2008 has proven to be a big undertaking. Every EntitySpaces template has been rewritten using our new metadata engine and is now supported in both MyGeneration and CodeSmith, many were converted from VBScript to C#. However, from this point forward we start knocking off issues on our roadmap in rapid fire fashion. We are a little behind on our May 15th release date, but not too far. Not only is the trial available for download but both the Developer version and Source version are available to customers as well.

    The testing behind this release is tremendous. We have two code generators in play, C# and VB.NET templates, and to top it off we had to debug Oracle subquery issues with messages like "ORA-923 No worky, try again" (kidding, but only slightly). Throw in database independence, the Compact Framework, and you really have your hands full. However, we are over the hump now and can see the light. This is a little off topic but we cannot wait to put up our Silverlight demo showing EntitySpaces working hand-in-hand with Silverlight. Our Silverlight demo is being worked on by Jon Davis and when we saw his first cut we were very impressed, Jon is a very sharp guy indeed.

    We've made some good changes too with our installs. Both our Trial and Developer versions install exactly in the same folder structures. This will avoid confusion for those folks who use the EntitySpaces Trial for a large part of their development process and then purchase the Developer version before going live. Now you can simply install the developer version right over the top of the trial and not worry about changing reference paths. This beta comes with all providers, including our Compact Framework providers, it also comes with a SQL CE desktop provider in addition to the Compact Framework version. The beta will automatically install into both MyGeneration 1.2 and 1.3 folders and add support for CodeSmith. See the Getting Started documents on your menu after installation. There is a "Getting Started.PDF" for both MyGeneration and CodeSmith. Just a quick note for our MyGeneration customers. If you have any user meta data defined for aliases or Oracle or PostgreSQL sequences be sure to run the UserData template. It will convert the MyGeneration user data file to our new format upon first run. From that point on you maintain your user meta data via our UserData template and not through MyGeneration.

    image

    You can see by the image on the right that the runtimes are easily found in the Runtimes folder. We have both .NET 2.0 and 3.5 assemblies as well as Compact Framework assemblies (we now use CF and not Ce for those in our naming convention). Also notice that the CodeSmith templates are under the EntitySpaces 2008 folder. The "Getting Started.PDF" for CodeSmith will show you how to setup a Template Folder Shortcut in CodeSmith, it's a snap.

    Our ES2007 EntitySpaces demo still hasn't been converted thus our ES2008 demo is very lightweight. We are going to rewrite it and not just convert it so that's the reason why we've held off. There could be some minor breaking changes coming when we tackle a few things on the roadmap, however that's not the usual case for EntitySpaces. We do want to address a few things to make your lives easier though.

    We really hope a lot of our users start taking a serious look at ES2008, our Subquery and Casting support is very powerful and we will have a ton of enhancements rolling out soon as we head for the official release. We have also prototyped LINQ to SQL with EntitySpaces. And even more exciting when talking to Jon Davis about Silverlight we spoke about adding the very popular EntitySpaces DynamicQuery API to our proxies as an option. You could then issue full ES2008 dynamic queries from within Silverlight (down in the client) and from other situations such as WCF conversations where you might not have EntitySpaces on the client. All of this is to say that when we release EntitySpaces 2008 that is not the end, but the beginning.

    We are very excited about where we are going and have a great vision for EntitySpaces. Not only can we run on Mono, Medium Trust, the Compact Framework, but we can provide seamless support for Silverlight as well. Mike Griffin will be demonstrating a lot of these high end features at the Indy ALT.NET meeting on May 15th.

    So download the ES2008 Trial and if you hit a snag please post on the forums and we'll get you a speedy response.


    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, 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.

    The EntitySpaces Team
    --

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

    posted on Sunday, April 27, 2008 9:22:04 PM (Eastern Standard Time, UTC-05:00)  #   
     Wednesday, April 23, 2008

    For those of you planning on attending the first meeting of the Indy ALT.NET community group on May 15th registration is now open. However, there are only 70 slots so please only register if you plan on attending.

    Register Here ==> Indy ALT.NET, a Technical Presentation of EntitySpaces 2008

    We hope to see you there. Finally, I am no longer banned from user groups as I have been my entire life. I personally hope the ALT.NET movement really catches on as we desperately need community groups that are not controlled by Microsoft where developers such as myself are allowed to speak. In the end, it will be the .NET users who benefit by seeing great .NET technologies, applications, and speakers that they might not have seen otherwise. I know ALT.NET means many things to different people, but that's how I see it and I think it's a great idea. You can watch for ALT.NET groups at altnetpedia.

    See this POST for more information on the EntitySpaces presentation including times and location.

    =============

    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.

    The EntitySpaces Team
    --

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

    posted on Wednesday, April 23, 2008 5:19:21 PM (Eastern Standard Time, UTC-05:00)  #   
     Wednesday, April 16, 2008

    On May 15th Mike Griffin of EntitySpaces will be giving an in-depth technical presentation on EntitySpaces 2008 in Indianapolis. This promises to be a real "EntitySpaces Under The Hood" session so if you're near Indianapolis we hope you can attend. We have room for 70 people. More information will be provided soon but we wanted to get the word out so you can mark your calendar if you are interested. A registration site will be posted within a week so you can reserve a slot.

    When:

    Thursday, May 15th. Doors open at 5pm, pizza served, presentation starts at 6pm and should go a couple of hours. So drop in anytime after work. There will be Q&A time as well.

    Where:

    Country Inn & Suites By Carlson Indianapolis North
    9797 North Michigan Road
    Indianapolis, IN 46032
    317-876-0333

    Click here for a MAP

    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, 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.

    The EntitySpaces Team
    --

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

    posted on Wednesday, April 16, 2008 10:37:21 PM (Eastern Standard Time, UTC-05:00)  #   
     Sunday, April 13, 2008
    kick it on DotNetKicks.com

    beach


    Vacation

    If you noticed that I wasn't around much on the forums this past week you weren't imagining things. I was on vacation in Palm Beach Gardens, Florida. It's truly paradise on earth. We went to Juno Beach almost every day (don't let the Jones Beach shirt fool you). I was there with my wife and three children and we played in the waves all week, it was awesome. Maybe I'll post some other photos later. I have to admit it's a little depressing to be back in Indianapolis and it's only 39 degree's here (it was in the mid 80's all week in Florida).

    During the evenings I was able to read the new LINQ in Action book published by Manning. I was particularly interested in the LINQ to SQL functionality and how it could be applied to EntitySpaces. Well, it's been less than 24 hours since I've been home and I already have LINQ to SQL working with EntitySpaces. The LINQ in Action book is pretty good as a LINQ reference but it really kind of ticked me off otherwise. The strawman it setup in order to tear down was really blatant. I think I could take nearly all of the the supposed samples it uses to show how much better LINQ is over ADO.NET and provide appropriate samples using EntitySpaces and it would be far more intuitive. I might just do that later to make a point.

    Okay, enough ranting, let's focus on using EntitySpaces with LINQ to SQL (for Microsoft SQL Server only so far).

    EntitySpaces and LINQ to SQL

    Adding support to EntitySpaces for LINQ to SQL was pretty easy. I added [Table] and [Column] attributes from the System.Data.Linq.Mapping namespace to my "generated" Employee entity like so:


    [Table(Name="Employee")]
    public partial class Employee : esEmployee
    {
        [Column(IsPrimaryKey = true, CanBeNull = false)]
        public override int? EmployeeID
        {
            get { return base.EmployeeID;  }
            set { base.EmployeeID = value; }
        }

        [Column]
        public override string LastName
        {
            get { return base.LastName;  }
            set { base.LastName = value; }
        }

        // more properties here ...
    }

    I had to make pass through's for the properties however. Recall that the properties are in the generated esEmployee class not the generated Employee class and the esEmployee class is abstract. LINQ cannot instantiate the abstract esEmployee class and it appears that the [Table] and [Column] attributes must be on the same physical class (no inheritance allowed). So I made overrides of the properties in my Employee class, applied the attributes, and I was ready to test. For more information on the inheritance LINQ limitation see this MSDN forum post.

    After making the above changes it was time to test it and see if worked. Below is my test code.

    DataContext dataContext = new DataContext("User ID=sa;password=; ... ");

    var employees = dataContext.GetTable<Employee>();
    var query = from employee in employees where employee.Age < 50 select employee;

    foreach (Employee emp in query)
    {
        Console.WriteLine(emp.Age.ToString());
    }

    As I suspected and hoped, it worked. However, semantically this is a little different that using our DynamicQuery API. I didn't get back an EntitySpaces EmployeesCollection class. Instead I was handed a System.Linq.IQueryable<BusinessObjects.Employee> interface which I could then use to enumerate over the individual Employee objects. However, these were my true EntitySpaces objects which was kind of cool. This is all still exploratory and is slower than using the EntitySpaces DynamicQuery API but still offers valuable functionality. We're pushing hard on the next ES2008 beta and as time allows we will sneak in some of these cool new features as time allows. My guess is this will make the first release of ES2008.

    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, 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.

    The EntitySpaces Team
    --

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

    posted on Sunday, April 13, 2008 12:32:08 PM (Eastern Standard Time, UTC-05:00)  #   
     Sunday, April 06, 2008

    We are cranking very hard on EntitySpaces 2008. However, we are doing many things in parallel. We thought we would take this time to relay some of work going on here at EntitySpaces behind the scenes and to relay some long term strategy. None of these side tasks are drawing tremendous energy away from our main focus, which is, EntitySpaces 2008.

     

    Side Tasks

     

    Silverlight

     

    We are working with a Silverlight expert to create a sample that demonstrates running EntitySpaces under Silverlight. These are the scenarios we are investigating:

     

    1) Hosting the EntitySpaces assemblies under Silverlight in the browser.

    2) Hosting our lightweight proxies under Silverlight in the browser.

     

    This research is just getting underway and will let you know more soon. The idea is to make it so that you can write Silverlight pages using EntitySpaces. We know in some form this will be possible.

     

    Site Redesign

     

    EntitySpaces is undergoing a site redesign and logo change. Our goal is to make the changeover simultaneously with the release of ES2008.

     

    LINQ to SQL

     

    There is some investigation underway that might allow our Microsoft SQL users to check a checkbox during the code generation process that would allow them to use native LINQ to SQL calls to populate EntitySpaces. This is very much at the beginning of the R&D process. However, we are not creating our own LINQ provider. If we can offer you LINQ through the existing providers then we will do so. We are very committed to our DynamicQuery API and will continue to expand it in big ways. In no way will LINQ replace our DynamicQuery API.

     

    The .NET Micro Framework

     

    We will investigate this at some point after ES2008 is shipped. Whether or not it makes sense for us to support the .NET Micro Framework we are unsure of at this time. We are committed to ensuring that EntitySpaces remains tiny and continues to run under all possible .NET environments. Our Mono support and Compact Framework support will always be very important to us.

     

    Long Term

     

    After we ship EntitySpaces 2008 we will begin to solidify the design goals of our next release. The ES2008 release essentially decouples us from any particular code generator. We now use our own metadata engine and essentially only use code generators to gather the user input and execute our templates. Our templates are really just normal ASP.NET pages with <% %> tags and literal content and this is inline with our long term goals.

     

    Visual Studio Shell

     

    We have done some investigation into the Visual Studio Shell (both integrated and isolated) and we think this could be the platform we choose to go with long term. This would mean that we would no longer use code generators and instead would do the code generation ourselves. Since the Visual Studio Shell supports isolated mode this has the added advantage of still supporting the smaller shops that cannot afford Visual Studio (integrated runs inside of Visual Studio itself).

     

    The Modeler

     

    EntitySpaces will support custom domain model building. We currently generate the hierarchical object model from the foreign keys in the database. In the future, and in conjunction with the VS Shell application mentioned above, you will be able to design your own object model that is not tied to the physical database schema. However, we will not use XML or other such devices at runtime, we will simply generate the code using your virtual domain model. We will still support our current approach which is solely based on the database schema also.

     

    Template Engine

     

    Imagine a template engine that is based on snippets. Currently we have Master templates which execute sub-templates where a sub-template might be and entity class, a collection class, or query class. Our new template engine will be based on snippets. A sub-template itself would merely be a collection of snippets where each little "set" of functionality is a snippet. Writing a snippet would be very simple and within the grasp of all developers.


    A snippet could be a property creation snippet, an INotifyChanged snippet, and so on. This would allow users to swap in their own snippets as well as to share them. Our standard templates would be based on many individual snippets. To customize or extend EntitySpaces would no longer require hand changing templates, simply restack and or replace the snippets through a UI not hand editing.

    Our shell based application would have its own underlying database which would store templates and other settings. You would be working with templates graphically, where each snippet is a different colored block. You could then right mouse on a snippet and choose remove it and drag and drop other snippets from the available snippet library onto a template to further customize it. Users will be able to post snippets to an online webservice hosted by EntitySpaces that our shell app will make available to all EntitySpaces users. At some point, after ES008 ships, we will post some images of our new approach.

    We feel this is going to revolutionize the way people view code generation as we will open this up to the masses, not to just code generation experts. The Visual Studio Shell combined with our new Modeler will take our already stellar architecture to new levels.

    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, 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.

    The EntitySpaces Team
    --

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

    posted on Sunday, April 06, 2008 11:24:03 AM (Eastern Standard Time, UTC-05:00)  #   
     Monday, March 31, 2008

    The first EntitySpaces 2008 Beta is available on our download page. If you have the Alpha installed you should uninstall it before installing the Beta. There is no need to uninstall EntitySpaces 2007, you can run ES2007 and ES2008 side by side.

    Limitations

    Only our Microsoft SQL provider is supplied with this Beta and there is no Compact Framework support yet. Finally, only the C# templates are included. MyGeneration and CodeSmith are supported however in this single install.

    New Features

    The EntitySpaces 2008 Beta includes sub queries and casting.

    Changes for our MyGeneration Users

    The EntitySpaces templates for MyGeneration now use there own user meta data. You will find a new template in the root of the EntitySpaces 2008 namespace in MyGeneration called UserData. The first time you run it the template will convert your old user meta data (if any) to our new format and file name (esUserData.xml). Also, you will need to re-setup any custom settings you have made in the Settings template (replaces esPluginSettings) located in the root also.

    Also, a gentle reminder that we cannot spend our time writing complex queries for our users. Look at our samples on our blog linked under "New Features" above.

    Summary

    We are now going to start converting our other providers (including our Compact Framework providers) very rapidly. It could be that we decide to release a beta before the schedule April 27th Beta as listed on our roadmap. So if you aren't using SQL Server there might be a chance to get started before April 27th.

    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, 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.

    The EntitySpaces Team
    --

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

    posted on Monday, March 31, 2008 2:50:18 AM (Eastern Standard Time, UTC-05:00)  #