in

ASP.NET Weblogs

A Portion of Buff

Everybody else had one, so...

December 2003 - Posts

  • Like falling off a blog

    I've been busy working on a good-sized project for Thoughtworks over the last 9 months, which is one reason for the lack of posts.  The other is that it's taken me about 9 months to think of something to write about.  Here's something I thought worthy of note:

    Neo is an open-source object/relational mapping tool (I'll probably get in trouble about calling it an O/R mapper by its author - he calls it an "object facade") developed by my colleague Erik Doernenburg then tweaked, debugged, used and abused on the aforementioned project.  At least a couple of other teams are using it now, and it's very close to a 1.0 release.

    Neo works by generating both .Net classes and database tables from an XML schema. It then creates a one-to-one mapping between the two (which is why I should really call it a facade) using ADO.Net and provides typed collections, factories and query mechanisms for working with the generated classes.  The resulting object model is remarkably simple to use and has saved us from much of the hell of manual persistance.  Let's take a look at an example:

    IDataStore store = new SqlDataStore(connectionString);
    ObjectContext context = new ObjectContext(store);
    Title title = new TitleFactory(context).CreateObject("TC1234");
    title.Price = 12.99M;
    title.Publisher = new PublisherFactory(context).FindSingle("Name = 'New Moon Books'");
    context.SaveChages();
    
    

    In order of appearance:

    • IDataStore - Provides a means for an ObjectContext to store and load DataTables.
    • ObjectContext - Provides a scope for objects to exist within, performs bulk load/save operations and helps manages the lifecycle of loaded objects.  It is backed by a DataSet which hooks all the entity tables together.
    • TitleFactory - Used for creation and location of objects.  Each entity class has its own strongly typed factory.
    • Title - An example of a Neo-generated entity class.  It is backed by a single DataTable (each instance represents one row in that table).
    • Price/Publisher - Two properties representing both a column entry and another Neo object.

    Neo, like ADO.Net, doesn't care where its data originates - we use SQL Server, local XML files and web services (using DataSets makes it easy to hook it up to a web service).  Working in-memory also makes testing much easier and quicker.  Our app was in development for about 4 months before it even saw a real database (which was probably too long in hindsight, but that's a different story).

    There are limitations, of course:

    • There is a one-to-one relationship between classes and datatables, which can make complex systems hard to model correctly. 
    • The only supported database at the moment is SQL Server, although it would be trivial to implement IDataStore for others.
    • Currently, Neo is really only suited to projects which have full control over their database schema.

    Anyway, go and check it out, and let us know what you think.  I can post more information and samples if requested.

More Posts