Saturday, November 15, 2008

NHibernate Loading of Super Class

Magic!!! Table with 10 records, but when everything is loaded, it became 30 records.

What happened here? I have a super class that is inherited by another 2 subclass and the mapping strategy use here is the table-per-hierarchy mapping. In a scenario where I have to load the superclass from the database to validate some information regardless of which subclass it is. The method always return 2 times more than the data found in the table.

Spending about an hour trying to debug and googling around to understand what when wrong here but the search was not very fruitful. I just cannot believe that NHibernate does not support such issue of loading of superclass only, without multiplying the records with each subclass that inherit the superclass.

No choice, I am back to the NHibernate document and check if I have missing out any critical config for the class elemenet on the hbm file. After reading thru the list in detail, I finally found a class element that describe (polymorphism (optional, defaults to implicit): Determines whether implicit or explicit query polymorphism is used.) something close to the problem I have. Thankfully after some testing to ensure it does not produce the problem I have, I concluded the solution to this problem is to define the superclass polymorphism element to explicit.

Thursday, November 6, 2008

NHibernate Parent and Child (One-to-Many) Cascade Option

While working on a parent and child (one-to-many) nested object recently, I encountered a problem with the child object not deleted when I tried to remove the relationship even when I set the cascade option to all. After looking around and found that Oren Eini have provided a good explanation on the different option.

To delete the children object when the relationship is removed, the all-delete-orphans option have to be used. This will removed all child objects and the children will not be an orphan (without parent).

I have to agree with him that cascade option required careful attention and can be easily overlook. It can create some bugs for you if your code are not properly tested.

Monday, November 3, 2008

SandCastle and DocProject

Having used SandCastle for generating all my code documentation for almost a year. I must say that it have done a great job for me (not sure for those consuming the documentation), as everything is automated using NAnt with CruiseControl.NET.

However, the initial setup is not easy, as there are a few things that need to be installed before it can work. Starting with the GUI will be the easiest but it cannot be automated. Therefore, the integrating of the generating of the documentation using NAnt is one of the option. CodeProject have any excellent article with a sample of a NAnt script for generating the help file. Be warned that the script is very long and might take a while to understand and know what changes are required for it to work in your environment.

Recently, due to too much parallel development work, this documentation have to be generated ASAP, so that my colleagues can consume them. Developing a project with distributed teams in different geographical location and time zone is a challenge and this document need to be shared in a more efficient way. So I was searching around and found DocProject which can publish the help file as a web application. Interestingly, I did not see much blog talking about the use of the DocProject, so decided to shared some opinions about it as I think it just great tool to have.

With the used of this tool, hopefully it will help to save my colleagues having to download a new version of the help file every time it is generated by SandCastle. To get the DocProject running is much easier than I thought as it integrated with the Visual Studio, except for a few more things to be installed. Of course the only setback I have now with this tools is that I need to integrate with CruiseControl.NET and using NAnt with msbuild task is sweet and easy except that I do not want to install VS on the CC server. Looking at the roadmap of DocProject, I do hope that this is part of the pirority.


Looking at the above image the whole NHibernate API is clearly visible. This is all done by creating a DocProject and include the NHibernate dll to the VS->tools->options->DocProject->External Sources. For those that are interested to provide some documentation to your code, I do urge you to look into the DocProject. Meanwhile, I will continue to try if I can setup the documentation generation with NAnt without the installation of VS but just the SDK.

Visual Studio 2010 and .NET Framework 4.0 CTP

Finally, the CTP release is here...

But looking at the overview, is seems like the focus of the release is weighting towards the team system. Download and see in detail what they have to offer, but... the download is almost 7GB! Happy downloading.. and hope is a worth while effort.

On the other hand, coming from the ADO.NET Team Blog, the update on the roadmap of LINQ must have left lot of developers confused and scratching their head. What actually hit me is how much should I trust M$ with their roadmap and vision. Will I be learning something that will only survive one release?

Did an initial try out on Entity Framework when it was first release and thankfully did not implement it on any real project as I personally think that the EF still have a long road ahead. Within a short time, there is even a vote of no confidence.

So let see, if there are any substantial release...