May 2005 - Posts

You’re either a fan of O/R mapping tools or you're not. Pretty much beside the point... I’m not.

 

On O/R mapping

O/R mapping tools generate a project that represents a database in an object oriented way. Usually this is done by generating an assembly the application is compiled against. The code is typed in the target programming language, this offers compile time type safety against the database wrapper generated last. The database wrapper also contains SCRUD (Select, Create, Read, Update & Delete) code to interact with the database.

 

What I find problematic

Keeping a database in sync with code in a different tool feels like a hassle.

Replacing SQL with something else seems like a silly thing to do. SQL has proven itself worthy over the years; it’s the right tool for set operations and relation data manipulation.

 

For me this seems like too much of a price to pay for compile-time type safety when interacting with databases.

 

A solution?

Next to the XML support in Cw (or Comega language) it also contains new language constructs to interact with SQL databases. Instead of creating objects that represent SQL syntax, they pulled SQL support into the the programming language (C#).

 

Similarly to what O/R mappers do (and unfortunately), the database schema needs to be kept in sync. When adding a reference to a database an assembly is generated. Thanks to VS.NET integration this can be done in a similarly to adding a reference to an assembly (references -> add database schema).

 

After adding a database reference you can have a go with SQL in C#!

 

results = select ProductName

            from od in DB.OrderDetails inner join p in DB.Products on od.ProductID == p.ProductID

            where od.Quantity > p.UnitsInStock

            group by p.ProductName

            order by ProductName;

   

Console.WriteLine("Products that have orders exceeding stock on hand.\n");

foreach( row in results ) {

    Console.WriteLine("{0}", row.ProductName);

}

 

 

The end for O/R mappers?

 

May be, especially if the SQL extensions in Cw become part of a future version of the C# language.

 

With SQL Server 2005, database development becomes more integrated with .NET programming concepts and the Visual studio IDE. Adding SQL syntax to .NET programming languages seems like an obvious next step.

 

 

hungry? I am! :-)

 

 

 

While .NET 2.0 fx (including C# 2.0) is still in it’s beta’s, some developers (including me) won’t get excited anymore by talk about generics, the yield statement, partial classes, etc….

 

Something that did is Cw (or Comega language).

 

Cw is a programming language, based on C# 2.0 that includes 4 language extensions from what I believe once were separate research projects at Microsoft. These language extensions are:

 

  1. Xml language support
  2. Sql language support
  3. Tuple support
  4. Concurrency support

All extensions are bundled into 1 compiler (which is still a preview version) and can be downloaded here. Read the language documentation over here. The compiler integrates with VS.NET 2003 and comes with sample source code.

 

A brief example of xml integration in c# sourcecode:


//returns the contents for a html table that

//displays x & y coordinates

tr* GeneratTableRows(Point[] collectionOfPoints)

{

       //yield the header for the html table

       yield <tr>

              <th>X Coordinate</th>

              <th>Y Coordinate</th>     

              </tr>;

      

       //for each Point in the given array, return a single row.

       //!!note that the contents of '<td>' is typesafe, therefore .ToString() should

       //be used. Anything else will result in compiler errors (and ‘editor squirlies’

       foreach(Point p in collectionOfPoints)

       {

              yield <tr>

                     <td>{p.X.ToString()}</td>

                     <td>{p.Y.ToString()}</td> 

                    </tr>;

       }

}

 

 

//in a referenced class the xml format is defined

//possibly generated using xsd2comega.exe!

 

//tr contains multiple th's or td's

//tr contains 1 atribute style, typed as a string.

public class tr {

       choice {

              th;

              td;

       }*;

       attribute string style;

}

 

//td is a block

public class td : block {}

 

//td is a block

public class th : block {}

 

//block contains multiple instances of either a, ..., block or string

public abstract class block {

       choice {

              a ;

              //...//

              block;

              string;

       }*;

}

 

A list of tools to support Cw development (cwc.exe, xsd2comega.exe, sql2comega.exe) can be found here.