1. Home
  2. Computing & Technology
  3. C / C++ / C#
photo of David Bolton
David's C / C++ / C# Blog

By David Bolton, About.com Guide to C / C++ / C#

MyGeneration - Open Source C# O/R Mapping

Tuesday August 19, 2008
I really love open source (yes I know that the iPhone and open source are incompatible- sad really) and some of the projects around are quite remarkable. I've been looking at MyGeneration which is a C# open source Code Generator and O/R (Object Relational) Mapper. This is working with data held in databases with an object wrapper around them. The idea is that the relational database tables are not accessed directly or through SQL but instead mapped onto classes which simplify the use of the database.

The code generator takes the tables for a wide variety of databases (12!) and produces the class code. It's template driven (not C++ type templates) so the code generator can output code for JScript, VBScript, C# or VB.NET. It's worth a look not just because it's open source but because of the architecture. This is what the C# looks like for accessing an employee record. (This code example is similar to one on the MyGeneration website).

Employees emps = new Employees() ;
if(emps.LoadByPrimaryKey(31))
{
    emps.LastName = "Bowman";
    emps.Save() ;
}

// Add one new record for Mr Archer
Employees emps = new Employees() ;
emps.AddNew() ;
emps.FirstName = "Mr.";
emps.LastName = "Archer";
emps.Save() ;

// get the last record index
int i = emps.EmployeeID;

Not a sql statement in sight! You'll find mygeneration here and the code on sourceforge. Note, you'll need another sourceforge project- the free 7z archive utility to extract the source code files.

Comments
August 20, 2008 at 10:25 am
(1) Justin Greenwood says:

I’m glad to see more people finding the value in MyGeneration (especially since it is free!). There’s a lot more to MyGeneration than dOOdads really, it’s a full code generation suite that enables “rolling your own” OR Mapper as well.

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore C / C++ / C#
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#

©2009 About.com, a part of The New York Times Company.

All rights reserved.