I'm ashamed to say it, but I have to. I have not worked with ORM's. I'm really considering NHibernate as it seems to be the most mature product for .Net out there (please correct me if I'm wrong). Now, the thing is that we have a big e-commerce/booking system with an SqlServer as the main integration point, containing quite a lot of business logic in sprocs. Now - obviously - this architecture is something we want to move away from, and we've been doing so for some time, piece by piece. So, my real question is how feasible is it to start using NHibernate for new features and not going back and map all the legacy stuff? Is this kind of gradual introduction of and ORM supported, and if so, would you recommend it?
If you are using legacy databases, you will find ORM tools rather difficult to use, configure, maintain and optimize. We ran into the many issues when we used NHibernate to map our Domain Model to an existing database. Some of them were:
The Model objects were difficult to map to existing tables (we had over a 100 tables), some of NHibernate's requirements were quite obtrusive like every table must have an ID field to be able to be mapped into a Domain object. Also, mapping many to many relationships was quite difficult to grasp and use.
Maintaining the large volume of mapping XML required to map to legacy database became a full time job for a developer and was quite challenging, specially in a team of 10+ developers.
Our queries degraded in performance as complexity grew since the Data model and Object model did not always match the busineess and needed to be constantly tuned. A large amount of data aggregation code had to be written. For example, if we needed to show a grid which joined multiple tables, we used to have to load multiple Domain objects put them together and show them in one grid. That code was hard to maintain and debug.
Also, sometimes we had to run anonymous queries, i.e. where we just wanted a few properties from some objects and not the whole objects. That was really difficult to write, maintain and even implement and was going against the ORM paradigm, but we had no choice but to do so.
Another problem we ran into was that the Database was constantly changing as the DBAs would refactor the tables and that would always break our Domain objects. It was an excercise to keep the Models and Tables in synch and also make sure the App still worked.
Long story short ... What we learned that if there was a way to map the SQL that business needed straight to our UI Model or Domain objects without having to worry about configuration, it would be a better solution.
After going through this experience we developed the Orasis Mapping Studio. It is a mapping tool specifically designed to work against legacy databases and also existing .NET Model / Domain objects. It takes your SQL queries and allows you to map them to your existing .NET objects by showing the metadata of the Query and the Object graphically and using drag and drop to create mappings between Object properties and Query columns. The tool automatically generates all the ADO.NET code you would need to perform your mapping to read your objects. You can then use the generated code in your DAL Layer or use the generated Assembly to retrieve and persist your data.
You can try it here: Orasis Mapping Studio. It is a tool that we believe developers really need, specially for working with legacy databases and where performance is a key requirement. It is written by developers for developers so it handles some of the intricate details like Obejct inheritance, nested objects, data type conversions, etc. Good Luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With