Thursday, May 26, 2005 9:51 PM Olaf Conijn

Cw: alternative to O/R mapping tools?

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! :-)

 

 

 

# re: Cw: alternative to O/R mapping tools?

Thursday, June 02, 2005 4:54 PM by Olaf Conijn

I think the greatest flaw in OR mappers is that the mapping functionality is too limited. I see a possible future for O/R mapping type of products if they start to support real mapping. And I do not mean the simple table to class mappings that you see today in these products.

In my view the true benefits of mapping are only realised when the mapper allows true mapping of datamodel to business entity model. I say this on the assumtion that you want to have a specialized business entity model for each problem domain to allow that problem domain to express its data in the most natural way to that domain.

These concepts will become increasingly important as we move to start building true SOA applications.

# Anders Hejlsberg on Programming data in C# 3.0

Monday, June 20, 2005 4:24 PM by TrackBack