Local and UTC Dates in NHibernate

How do you get a UTC datetime hydrated from NHibernate? Dan Morphis addressed this a while ago with an interceptor.

I proposed a patch to NHibernate that adds UtcDateTime and LocalDateTime data types that will specifically get hydrated with the proper DateTimeKind value instead of DateTimeKind.Unspecified.

Usage
<property name="MyDate" type="UtcDateTime"></property>
<property name="LocalDate" type="LocalDateTime"></property>

You download the patch from Jira, and vote for it if you like it.

Alt.net IS NOT Devisive

For those thinking that alt.net is negative and is divisive I remind of you David Laribee’s post several months ago about proposing the alt.net name. Now how can that mission be unclear, divisive, or negative?

If you have been doing agile, ddd, tdd, bdd, mvc, orm, ioc, di, and ci before alt.net, fantastic, so have most people in the software world. Alt.net is more than acronyms, practices, and tools. Its a mindset. Its trying help other .net community members think critically about their software and how their building it.

It is not about dictating policy, practice, or tooling. It is not about alienating people or ideas. It is about trying foster new growth within the .net community itself.

We can never be sure that the opinion we are endeavoring to stifle is a false opinion; and if we were sure, stifling it would be an evil still.
– John Stuart Mill

NHibernate To DataSet

Ayende just posted a very simple solution to converting the result of an NHibernate Query / Criteria to a DataSet. Here is something that I have used in the past.

public DataTable CriteriaToDataTable<CriteriaClass>(ICriteria query,
																										String dataTableName,
																										params String[] properties)
{
	DataTable dt = new DataTable(dataTableName);
	int i;  

	foreach (String prop in properties)
		dt.Columns.Add(prop.Replace('.', '_'), ReflectionUtil.GetPropertyType(typeof (CriteriaClass), prop));  

	foreach (Object obj in query.List())
	{
		i = 0;
		Object[] vals = new Object[properties.Length];
		foreach (String prop in properties)
		{
			vals[i] = ReflectionUtil.GetPropertyValue(obj, prop);
			i++;
		}
		dt.Rows.Add(vals);
	}
	return dt;
}

Read more »