Why doesnt the generated NHibernate classes automatically detect nullable dates?

I had to open all the generated classes and manually enter a ‘?’ at the end of each DateTime type for each of my nullable dates.

Example:

Codes generated by DB-VA

 
private DateTime __approvalDate;

public DateTime ApprovalDate{
    set {
        this.__approvalDate = value;
    }
		
    get {
        return __approvalDate;
    }
} 

I have to change it like so… (so it accepts null date column)

 
private DateTime? __approvalDate;

public DateTime? ApprovalDate{
    set {
        this.__approvalDate = value;
    }
		
    get {
        return __approvalDate;
    }
} 

Any reason for this behaviour? Or am I doing it the wrong way?

Hi user,

I already forwarded your question to our engineers. I will come back to you once I have received a reply from them.

Best regards,
Jick

hi user,

I regret that the current version of NHibernate does not support nullable types.

Best regards,
Jick

But .NET 2 does. The fact that by simply adding a single question mark ‘?’ on each datatype is enough to do the magic.

Right now I have to browse to all the generated classes and change every single datatype to its nullable counterpart. This is very painful. Now imagine if I have to regenerate the classes again due to some database schema changes or anything, I will have to redo all over again.

Is there a way to automate this? Or at least make it an option during the NHibernate class generation to use appropriate nullable datatype for every nullable column in the database.

I am sure it is very easy to do. But then again I am not the developer so I can only guess.

How does everyone else doing this? I am curious. Right now I am noticing that if I dont use nullable types, every int column in my database will become 0 if I dont assign any value, which is not really what I want. For date, it throws date overflow exception since Date.MinValue in .NET and in database is not identical.

Once I put a ‘?’ on these datatypes, everything work wonderfully and exactly as I expect.

Hello rosdikasim,

After a discussion, we decide to support this. But this will not be available in the current version. Do you want to try this as soon as possible? If yes, I will send you an early access release once it is ready.

Best regards,
Jick

Really?.. really really??.. that would be AWESOME!!!.. I would love to!!..

To tell you the truth I am still on trial license which will expire in 9 days.

I have no choice but to pay hehehe…, I am addicted. You guys saved me a few months of hard work! DB-VA is aaaaaaaaawesome!!

Hello rosdikasim,

You are welcome. Thank you so much for your valuable suggestion. In fact, this fix is ready in Service Pack 2. Do you need it now? If yes, I can arrange an early access release for you.

Best regards,
Jick

Hi Jick… yes please!.. if it is okay for you please send me the patch… I love to be on bleeding edge!

Hello rosdikasim,

Just a note to inform you that Service Pack 2 is released. You are suggested to run the product updater inside the bin folder of VP Suite installation folder to advance to the latest release.

Please feel free to let me know if there are any questions.

Have a nice week!

Best regards,
Jick