Felice Pollano Blog

The Official Fatica Labs Blog

About the author

Author Name is someone.
E-mail me Send mail

Recent posts

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

A textual DSL for NHibernate mapping

I'm working on a little project to satisfy my idea on creating a mapping for NHibernate describing the model entities in a notepad like fashion. The application I created leverage a new SDK from microsof, at present in CTP: Microsoft Oslo SDK.

The application starts from a very simple language, and starting from this creates the clsses, the hbm's and the database script ( Database script at the moment does not work... ;)

). The application deal with collections,references, subclassing, and many-to-many relationship.

Lets have a couple of screenshot, the first one about a relation Books-Authors...

  This is the hbm (whit all the mapping in a single view ):


and this the mapping ( all the classes in a view):

 



A sample with subclassing ( a just for fun financial model )

 




Well, there is still some bugs, but the application really do what expected: a lot of boring code line autogenerated from an intuitive textual DSL.

Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: NHModeller
Posted by Felice on Tuesday, February 17, 2009 3:40 AM
Permalink | Comments (9) | Post RSSRSS comment feed

Related posts

Comments

Fabio Maulo

Tuesday, February 17, 2009 3:31 AM

Gravatar

I'm happy to see somebody saw the light...
http://fabiomaulo.blogspot.com/2008/12/light.html

Fabio Maulo

Tuesday, February 17, 2009 7:06 PM

Gravatar

Are you interested to make public part of the code (under LGPL) ?
We are specially interested in the part of hbm creation.
What we would do is create mappings before build the sessionFactory

Felice Pollano it

Tuesday, February 17, 2009 7:12 PM

Gravatar

At present I've not yet an idea on how to distribuite the product ( or portion of it ). It could be an LGPL project if I find some finances.

Mike Mould ca

Friday, March 20, 2009 2:36 PM

Gravatar

Felice, this is the most senseless idea about mapping helpers tool. You oblige the developer to write code…….
The graphical approach (like LINQ to SQL) allow easy and quick mapping.

Felice Pollano it

Thursday, March 26, 2009 6:39 PM

Gravatar

Mike,
Thanks you for leaving your opinion.
The approach I show is a little different. Using the Linq To SQL graphics tool you need to design the database before, and then you drag your table in the design surface. You need to mantain your work in two places. With the textual DSL you write something very specific in a single point. You are right, I'm forcing the user to write code, but, at least, only once, and with a few lines I generate a lot of code in term of artifacts ( there is a big leverage effect). In addition, not all programmer likes graphical dsl ( me as well ). Is a matter of choice.

Frank J Caruso us

Sunday, April 05, 2009 10:08 PM

Gravatar

Hi to alls.
Mike: sorry but I disagree with you. This seems to be a nice and useful environment for mapping. The ‘graphical approach’ is another manner to work. They are incomparable.
Fellice: unfortunately this idea is not a lot original: try to googling a few and you will discover at least four analogous solutions (of course: GUI and pseudo-language are different).
Regards….

Felice Pollano it

Wednesday, April 08, 2009 8:16 PM

Gravatar

Frank,
Thank you for pointing the difference between a graphical approach and the textual one.
I did googled in the past, and found a lot of helper tools for nhibernate but the solution I propose is a little different. Most tool are in a certain way asymmetric: you start from one final point, and generate the others. The DSL approach centralize the mapping overall idea, and generates all the dirty stuff from an ideal ( or, at least, near to ) way of representing the model. In other words, even a non programmer can start to drop down some ideas and have a working program. I don't know if there is a unit for measure how a code generator is good: we can ideally think such a measure as a ratio from the countof keystroke instructing the generator by the resulting code equivalent count. If such a measure exist I think the solution I'm proposing will give a good performance.

PeteGoo nz

Wednesday, April 08, 2009 11:26 PM

Gravatar

Hi Felice,
I really like this idea. I've spent the last 2 years building similar graphical tools (DSL Tools for VS) for our own internal use and I'm now looking at oslo quite seriously. One thing that confuses me is your syntax for associations here, I'm not sure what this is supposed to convey, I would probably have gone for something like Authors: Author*. Just a suggestion.

Also, did you do the graph to model conversion manually or via XAML?

Thanks,
Pete

Felice Pollano it

Thursday, April 09, 2009 9:03 AM

Gravatar

Hi Pete,
Actually the syntax you describe works too when the "right hand side" of the association is unique ( and actually is in the example ) so we could write Authors:Author* and Books:Book* with the same result. I decided to shown this syntax for completeness: you may have more than one end point on the same entity, and further you possibly would like to specify what is the "inverse " end point of the relationship.
I did the Graph visit manually. Don't know if it is the best way... I've a lot to learn on oslo too :)
I'm just asking the oslo team if it's ok for them, on placing NHModeller as open source, stay tuned :)

Comments are closed