Using Guid as Id column in NHibernate causes format exception when using MySQL

guid, mysql, nhibernate

Solution

MySql Connector documentation states that from version 5.2 of .NET connector they treat GUID's as BINARY(16) not VARCHAR(40).

Since current MySQL dialect in nhibernate doesn't updated to reflect this change (actually an issue is prepared) you need to manually convert these fields to BINARY(16) after nhibernate generate the schema.

Problem

When I define the NHibernate entity/mapping to use Guid as identity column I receive an exception. The Guid column is generated as a varchar(40), but the content seem to be binary. Is there a solution to this? For now I'm just using plain ol' int, but it would be nice to know for future projects! :)

Original source