I have only started experimenting with NHibernate and couldn’t get my head around the following scenario, hope someone can shed some light on it. Thank you.
I want to refactor existing Data Access Layer from Subsonic to NHibernate. The existing database is using BINARY(16) as primary key. In Subsonic, it has no problem dealing with byte[] as primary key. In NHibernate if I attempt to map a property that has byte[] datatype, I’ll come across the following exception messages:
{"Illegal use of an array as an identifier (arrays don't reimplement equals)."}
Example of my entity and mapping (with FluentNHibernate) as following:
public class Product
{
public virtual byte[] Id { get; set; }
public virtual string Name { get; set; }
public virtual string Description { get; set; }
}
.
public ProductMapping()
{
Table("tblProduct");
Id(p => p.Id).Column("prdProductGuid");
Map(p => p.Name).Column("prdName");
Map(p => p.Description).Column("prdDescription");
}
Is there a way to workaround this issue? Thank you.
Currently working with .NET 4.0, NHibernate 3.3.1 and MySQL 5.1.52.
I had a look of Hibernate community and found a hint on utilizing
IUserType.I’ve created a custom class Bytes that’s essentially a serialized wrapper for bytes array:
BytesUserType:
Updated my entity and mappings:
.
And that does the trick!