开发者

Mapping a primary key of type binary(16)

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开发者_如何学Go 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?


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 ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜