Problem with nhibernate, mysql and guids

I have a view that aligns a hierarchy of 4 tables to display as a report. in the view, it contains the primary keys (Guid) of each table along with some displayed data.

The problem is that as returned characters it returns as varbinary (16) instead of binary (16), and as a result, nhibernate throws an error. It seems to me that this is one and the same, but maybe I'm missing something.

The manual should contain 32 digits with four dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

I tried to add Respect Binary Flags = true; to the configuration line, everything that seems to affect whether regular classes work or not.

This one annoys me. I am going to return primary keys to integers as a last resort.

+4
source share
2 answers

This is an error in the Mysql.net connector to check this error report for more details. http://bugs.mysql.com/bug.php?id=52747

UPDATE: After version 6.1.1, you should add "old guids = true" to the connection string whenever you use BINARY (16) as the storage type. In addition, you should use CHAR (36)

+1
source

Solution: create a custom dialect

public class MySQL5GuidFixDialect : MySQL5Dialect { public MySQL5GuidFixDialect() { RegisterColumnType(DbType.Guid, "CHAR(36)"); } } 

Remember to configure it in your NHibernate configuration. I prefer CHAR over VARCHAR because it uses (or should use) static alloc instead of dynamic for fixed-length fields

+3
source

All Articles