Astoria and Jasper: Old Ideas New Technology

October 18th, 2007 Comments
Microsoft .NET

SubSonic is an excellent open source DAL generation tool developed by Rob Conery that has been around for almost a year. In most cases SubSonic can just be added to your project, pointed to a databse, and you magically and immediately gain access to a rich and strongly typed object model that can be used to query and persist data to and from your relational data source.

SubSonic also has a cool feature called the REST handler that essentially allows one to use HTTP protocol as an interface to data stored in a back-end relational database. It is URI based and returns data back in XML format. This data can then be used by decoupled client applications as they see fit. If you have never looked at SubSonic, you owe it to yourself to checkout this very cool tool.

Recently Microsoft unveiled their plans to release similar features codenamed Astoria and Jasper with .NET framework 3.5 and Visual Studio 2008. The CTP of Astoria and Jasper are available for download from Microsoft.

Jasper is described by Microsoft as:

Project Jasper is geared towards iterative and agile development. You can
start interacting with the data in your database without having to create
mapping files or define classes. You can build user interfaces by naming
controls according to your model without worrying about binding code. Project
Jasper is also extensible, allowing you to provide your own business logic and
class model. Since Project Jasper is built on top of the ADO.NET Entity
Framework, it supports rich queries and complex mapping.

Pablo Castro, the mastermind behind Astoria describes it as:

The goal of Microsoft Codename Astoria is to enable applications to expose data as a data service that can be consumed by web clients within a corporate network and across the internet. The data service is reachable over HTTP, and URIs are used to identify the various pieces of information available through the service. Interactions with the data service happens in terms of HTTP verbs such as GET, POST, PUT and DELETE, and the data exchanged in those interactions is represented in simple formats such as XML and JSON.

The Astoria web site also includes sample online services that showcases how this new technology can be used. It also allows anyone with a Passport account to design and host their own experimental data services .

ASP.NET GridView And Conditional Images

September 14th, 2006 3 comments

Depending upon a value in the data source, we can conditionally display images in GridView columns. For example, the following TemplateField declaration conditionally displays approved.gif or unapproved.gif based on IsApproved flag in the DataSet that the GridView is bound to:

<asp :Image ID="ApprovalImage" runat="server" ImageUrl="" />

ADO.NET Calculated Columns

September 9th, 2006 Comments

ADO.NET offers the capability to add calculated columns in typed DataSets and use the Expression property of the those columns to specify the formulae for calculations. What I did not realize is that you must use the Fill method of the adapter instead of the Get method for calculated columns to properly populate. For example:

using (MyTableAdapter adapter = new MyTableAdapter())
{
    MyTypedDataSet.MyTable dt =
          new MyTypedDataSet.MyTable(true);
    adapter.FillData(dt, beginDate, endDate);
}

Get Table Schema Programatically

August 18th, 2006 Comments

In order to retreive table schema programatically, we can use the GetSchemaTable method of the DataReader as follows:

using (OleDbConnection cn = new OleDbConnection())
{
    OleDbCommand cmd;
    DataTable schemaTable;
    OleDbDataReader reader;

    cn.ConnectionString = @"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind;Data Source=(local);";
    cn.Open();

    cmd = new OleDbCommand("Employees", cn);
    cmd.CommandType = CommandType.TableDirect;

    using (reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo))
    {
        schemaTable = reader.GetSchemaTable();

        foreach (DataRow row in schemaTable.Rows)
        {
            foreach (DataColumn col in schemaTable.Columns)
                Console.WriteLine(col.ColumnName + " = " + row[col].ToString());

            Console.WriteLine();
        }

        reader.Close();
    }

    cn.Close();
}