I have a legacy schema that contains tables with composite keys where some of the keys are of type binary(16) -- its a MD5 hash of the other columns. I am having trouble finding the right way to map this structure. The first thing I tried was to simply use byte[] as my domain type, which NHibernate quickly dismissed since byte[] does not implement Equals (duh!). The next thing I tried was to create a custom user type (i.e., implements IUserType) to wrap the byte[] and provide the requisite Equals implementation but this did not work since it appears that NHibernate (v2.1.2) does not support user types in composite keys. The last thing I tried was to use Guid as my domain type hoping that NHibernate would automagically CAST or CONVERT between my domain type (uniqueidentifier) and my column type (binary(16)); it did not. I am currently looking for a way to force NHibernate to wrap all usages of a column c in a CONVERT(uniqueidentifier, c). Is this possible or is there another way to make this work?
A:
I don't know nhibernate, but I think this is really an SQL question.
Any reason you can't create a view on the table, and add a new indexed field (I'm assuming ms-sql here) or similar that casts the binary(16) or a uniqueidentifier or nvarchar ?
Roger Willcocks
2010-07-07 05:25:13
This is an interesting solution but does not work for my case since this schema is deployed at many customer locations. I really need a solution that works with the schema as-is.
Faron
2010-07-07 11:27:19