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