浙林龙哥

   :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
By Rajesh Sadashivan

Overview and Resources for ORM and Codegeneration.

Aim of the article.

Recently I was asked to evaluate if some of the Open Source Code generators and ORM Framework can be used for building database applications. It was interesting as well as very good learning experience. This article tries to provides an overview and links to resources, which might be useful for developers to decide (or convince your boss) about need and utility of ORM/Code generation tools.

Introduction

Though we probably don’t realize, we have been using code generation since the day we compiled our first C(or assembly program!) program. The C compiler converted our C program into code that is understood by the machine.

Code generation can be defined as

conversion of an abstract text/model into more concrete artifact that can be finally understood by the computer (probably after several more iterations of conversions)

The main purpose here is to eliminate writing repetitive and static code that can be auto generated.

With every new release of developer tools from Microsoft, some parts of mundane coding tasks have been automated. The days when I used to type in 100 lines of code to create a simple “Hello World” windows application, now seem so naive.

With the need for writing code to generate UI screens almost eliminated (thanks to Visual Studio and other such IDEs), and programming becoming more abstract, the next target is automating application development for enterprise applications. Model Driven Architecture (MDA) is a step towards this direction that focuses on domain and process models as means of application generation. There are quite a few tools (mostly commercial) available, claiming to help you realize Application Generation. But due to prohibitive cost, proprietary architecture, and complexity, their acceptability and proliferation is still low. Most of the current tools available claiming to be MDA tools are advanced CASE Tools, or code generation tools, but we are surely getting there.

For more details please check the following links.

http://www.omg.org/mda
What You Need to Know About MDA?
MDA Tools, How to Select?
Is MDA ready for Market?
MDA Success Stories
List of MDA Tools

With so much momentum behind MDA, is Microsoft going to be left behind? Rumor has it that it is working on something similar that is different from the current MDA approach which focuses on UML; the project is named Project Green. Though not much is being said about this “secret” project, it is sure to give custom application vendors some scare.

Project Green
Demand App and Project Green

Check out some Interesting products from IRISE and also http://www.softrocksystems.com/, supports application simulation using UI Models.

Till these tools get cheaper, and easily available (so that I can get a copy and evaluate them in my spare time), let’s focus our attention to ORM and code generators which can automate creation of data access layer and web pages for at least for CRUD operations on Database tables.


Why automate Code Generation for CRUD?

* CRUD operations are very common and are required by almost all enterprise applications.
* Code is repetitive and Error prone.
* Code automation can reduce the effort required to test.
* Can lead to enforcement of best practices and coding standard.
* Can integrate with Open Source Data Access Framework, which can lead to increased productivity and “free” enhancements (also remember the downside of choosing a bad Open Source product)
* And did I mention it can save time so that you can go home early!


DAL s /ORM

In a Database application, Data Access Layer acts as a bridge between the Data Tables (Relational Universe) and Business Objects (Business Domains); and in .NET world, more often than not, these are built as an extension to ADO/.NET Datasets/Data tables. There is nothing wrong in this approach. In fact, it will work very well for small database applications. But for a large enterprise application where there are associative relationships and inheritance hierarchies, this approach doesn’t work well. In this scenario, we end up writing complex class hierarchies and utility classes to do mapping, transformation, and messaging of data. These issues are best addressed by totally separating Relational Model (the database) and persistence/mapping layer and Domain Model (Business layer).

Read an interesting comment in the following article by a well known ORM evangelist.
Fallacy of Data Access Layer

Object Relational Mapper, as the name suggests, provides framework which maps Relational Data to Objects (Business Objects).

If you are interested in detailed explanation about the theory behind ORM, please check the following links
Theory of OR Mapper
Simplified OR Mapper Explanation
.

Many of the OR Frameworks generate (or require you to create manually) classes (objects) based on domain models, while their framework classes take care of mapping and formatting the data, so that it persists safely and accurately.

There is a considerable amount of interest in the developer community with regards to ORM, and many perceive it as the next big thing in software industry. So when there is so much going around, can Microsoft be far away? Absolutely not; they are working on something similar. Long back, they had announced that they will have some thing on ORM, which was then termed as Object Spaces. It was supposed to be released with .NET Framework 2.0, but it was conspicuous by its absence in the beta release.

Here is the link to MSDN which currently doesn’t give much information. http://msdn.microsoft.com/data/objectspaces.aspx

But here are few links that provide you some insight into Object Spaces.


First Look at Object Spaces
Getting Started with ObjectSpaces
VS.NET Team member’s Blog on status of Object Spaces

Can Microsoft folks think a lot differently from the mere mortals? Well check this out Cω (C Omega). Comega, or Cω, is described by Microsoft as a strongly typed, data-oriented programming language to bridge semi-structured hierarchical data (XML), relational data (SQL) and the .Net CTS (Common Type System). Additionally, Comega extends C# with asynchronous concurrency abstractions.

Interesting Discussion

What are the ORM tools available for .NET in the market currently?

There are lots of ORM solutions available for Java (guys, its just because its been there few years ago OK :) ); but surprisingly there are quite a few solutions available for Microsoft .NET. Here is the SMALL list(thanks to Yves Reynhout and Sharp Tool Box)

.NET Persistence
CodUS
BizBlox
DataObjects.NET
Data Tier Modeler for .NET
DotNorm
DooDads
Eldorado.NET
Enterprise Core Objects (ECO™)
Entity Broker
eXpress Persistent Objects for .NET
Genome
Gentle.NET
JC Persistent Framework
LLBLGen Pro
ModelWorks
Nhibernate
Neo
Nolics.NET
Norm
Norpheme
ObjectBroker
ObjectPersistor.NET
ObjectSpaces
ObjectSpark
Objectz.NET
OJB.NET
OPF.Net (Object Persistent Framework)
ORM.NET
Olymars
Pragmatier Data Tier Builder
RapTier
Sisyphus Persistence Framework
TierDeveloper
Versant Open Access
Wilson's OR Mapper

Some other interesting frameworks

Data Access Library
Data Access and Transaction Framework
Unified DataAccess Framework
Provider Factory
Generic ADO.NET
Abstract ADO.NET

To see the updated list, please visit Sharp Tool Box's List of OR Mappers (Sharp tool box website contains wealth of information about various tools available for .NET be sure to visit them frequently at http://www.sharptoolbox.com/.)

Also Microsoft is working on Data mapping Application Block that will(was supposed to) be shipped as a part of Enterprise application block (any connection with ObjectSpaces :-?).

For more details visit Data Mapping Application Block Work Space

Criteria for Evaluating ORM Tools

With so many of these tools/framework available, which one to choose?

Well! If the answer was simple enough, we probably would not have so many products in the market. The best advice available probably will be to evaluate products against the requirements you have.

Some of the common Criteria that you can use
* Support for class hierarchies and relations
* Support for Grouping and Aggregate functions
* Support for Transactions
* Database Independence (If it’s not a major concern for you, you might want to ignore it. In some cases you might be able to eek out some performance gains)
* Concurrency
*Performance and footprint
* Data caching, lazy load
* Learning Curve, and simplicity with which it can be integrated with the code
* Some other points that need to considered are maturity, and available documentation, or community support.

Fabrice Marguerie has provided a detailed list of criteria that you can use to evaluate an ORM tool Evaluation Criteria for ORM

If you want to read some interesting debates about which ORM is the best please check out the following discussion (have a cup of Coffee ready it’s a long night!)
Which ORM is the BEST?
Which ORM?

I will try to give an overview on few of these technologies in another article. I plan to start with Nhibernate. Nhibernate is very flexible and is a part of a highly popular and established Hibernate Framework for Java.

It provides you with a frame work for eliminating/reducing (I prefer simplifying) the amount of code that needs to be written for the DAL.

Code Generation

Wouldn’t it be nice, if there are tools that, given a database and a table in that database, does whole bit of magic, and generates a C# solution, which will have GUI for all the basic CRUD operation along with the DAL?

You bet that would be nice!! Well, we are not alone; there are a whole bunch of people who thought of this before us.

To get the list of these tools you just have to click the link! C# Code Generators

I have personally used IronSpeed (it is much more then a code generator), and is good at what it does. It also makes, creating "Professional looking" database application very simple. But it’s not FREE and also does a lot of things "magically", without allowing me to control them (newer version allows more control though)!

Some of the Free Source code Generators are

MyGeneration A highly recommended Template based code generation engine, written by Mike Griffin and Justin Greenwood of MyGeneration Software. They have also committed to keep version 2.0, which is planned for release end of 2005 as a free product. With ASP-like syntax, flexible UI, and good Community and Developer support its a product that's ready for prime time.

CodUS Codus is a comprehensive code generation tool for object-relational mapping. It takes an existing database and automatically generates all of the code for updating, deleting, inserting and selecting records. In addition, it creates web services for distributed programming, strongly-typed collections, and a full set of unit tests. I haven’t got an opportunity to test this product, but it looks very promising (hopefully I shall get an opportunity to experiment with it soon).

Olymars SQL Server Centric .NET Code Generator (code named OlyMars) is both, a flexible and powerful code generator based on database modeling. This is a free and unsupported product from Microsoft. I haven’t been updated for quite some time, hence found it a little difficult to understand and use.

Nvelocity based on Velocity a highly popular template engine for JAVA. This project has been abandoned for lack of community support.(Come on .NET dudes wake up let’s start building strong Open Source community, Aren’t we fed up of taunts from these JAVA Guys.)

M3rlin is a template Code generator that uses ASP.NET style syntax. It hosts the ASP.NET runtime to perform the code generation. It uses XML as it is the source of meta-data.

MyGeneration so far as I have understood stands above the rest of the lot, with its flexible template based approach (in 4 different languages- JScript, VBScript, C#, and VB.NET), long term commitment from the Developers, and an active community support.

For Details please visit

http://www.mygenerationsoftware.com/.
My Generation Documentation
http://www.codeproject.com/dotnet/GriffinMyGen.asp
http://www.codegeneration.net/tiki-read_article.php?articleId=62

I hope you find this article interesting and useful. Till next time, Keep Learning!

Rajesh Sadashivan


Click here to view Rajesh Sadashivan's online profile.


posted on 2005-08-29 17:18  浙林龙哥  阅读(815)  评论(1编辑  收藏  举报