Monday, March 28, 2011

DataObjects.Net Entity Model Designer - Model First (Part 2)

Previous parts: 
Part 1 - Prologue.

As i mention in previous part of this article, my first attempt to create DO.Net entity classes generator fails because of complexity of tool itself and because of few other things.

Then i go another way, way of DSL designer. Begin was so hard due to lack of detailed documentation and really simple tutorials how to start with DSL (yes there are some articles, samples, but they aren't simple to understand in short time, and have no good examples either). I have devoted more time to learn DSL from scratch. Finally i released public alpha version of DSL designer to model DataObjects.Net entities.






Project Plan

Now:
First version (and subversion's) will be focused to make bullet-proof designer and T4 template to model first DataObjects.Net entities.
In other words to bring minimal set of required features to DSL designer and T4 template and fix bugs founded in those versions.

Next:
Next major(minor?) version will bring new feature - Import Database Schema (extracts existing database schema into model diagram). There are no details when i start to develop such version, it depends on finalizing first version (as described above).

Project License and Download

Project itself is freeware, but it is not provided with source codes.
Product is hosted on codeplex.com - http://doemd.codeplex.com. You can download MSI installer of project on codeplex.com site, under tab Downloads.

Features supported so far in first version of DataObjects.Net Entity Model Designer

Designer support 4 kind of persistent type:
  • Interface
  • Entity
  • Structure
  • Typed EntitySet

Inheritance (single or multiple) is supported:
  • Interface, Entity and Structure can define multiple (0..*) inheritance from other Interfaces 
    • equivalent to C# where class or interface can inherit multiple interfaces
  • Entity can defined base entity type
    • equivalent to C# where class can inherit only from one other class

Property Associations:
  • Persistent types (all but Typed EntitySet) can define reference property with multiplicity:
    • Zero to One (0..1)
    • One (1)
    • Many (0..*)
  • Property Association defined as multiplicity Many can define custom EntitySet type (Typed EntitySet)

Typed EntitySet (custom EntitySet):
  • Persistent type of kind Typed EntitySet will generate collection like class derived from Xtensive's EntitySet. This allows customization on such custom type.

Read more in Documentation on codeplex.

      DataObjects.Net Entity Model Designer - Prologue (Part 1)

      As i wrote earlier, i discovered best ORM framework - DataObjects.Net.
      After some time working with this framework on small projects i want to jump to big old one project with approx. ~500 tables divided into ~10 schemas. Then i realized that it wil cost too much time for me to write business entities for these 500 tables (including huge inheritance tree, relationship, associations,...). My first idea was to found some existing tool/addin, something to help me generating such business classes from existing database. Result was, there isn't any tool which support DataObjects.Net as target framework.

      If i need some tool/application and can't find it, i will try to write such application on my own (sure i don't write new Office or something like that :-)). My thoughts are that many developers do the same thing.

      I know nothing about Visual Studio DSL designers, so i decided to create Windows application. I started to write application where i can enter connection details (only MS-SQL servers), select required tables/columns and finish button to generate business classes from existing database. Next feature of tool was to read relationships from db and generate association properties with [Association] attributes on it.

      Firstly i think it is easy to do such feature, list of associations where i define source, target, properties of each (Multiplicity, On owner/target remove action, etc...). Again everything works like a charm, generated classes now contains reference properties, simple and advanced (multiplicity Many *, as Entity Sets) with required [Association] attribute(s).

      Whats the problem here, you can ask, give us such tool, right now. Well No!
      I figured out one big problem with such tool, when i import database with ~ 500 tables into tool, that list of generated associations (yes tool will automatically scan and detect relationships and create associations) was too big, for my db about 50 generated associations (where the tool cannot detect all kind of possible associations).
      Now when i look at associations list i have about ~50 rows of associations with information's like Source Property, Target Property, Source Multiplicity, Target Multiplicity, Source On Owner Remove Action... 50 rows of flat view on associations. Starting to review all of this generated associations, i lost myself on about half.I cant imagine visually in my mind association tree on these associations - some kind of "Diagram" to see which entity is associated to other one, in nice visual form.

      Here story of old "DO.Net Generator tool" ends, and new story of DataObjects.Net Entity Model Designer starts.

      Next part 2: Model First