We're working with Fluent NHibernate 1.2 and our primary key is a guid saved in a nvarchar(32) column, working with Oracle 11gr2.
How can we make this work? (making an automatic conversion...)
Thanks ahead, random programmer...
UPDATE: forgot to mention, the guid is saved WITHOUT dashes ...
Fluent NHibernate offers an alternative to NHibernate's standard XML mapping files. Rather than writing XML documents, you write mappings in strongly typed C# code. This allows for easy refactoring, improved readability and more concise code.
You will have to implement your own IUserType to handle the dashless Guids.
You can read about it here:
http://dotnet.dzone.com/articles/understanding-nhibernate-type
The detail below is now irrelevant to the question but I'll keep it here for future reference for people to find.
In your entity the Id should be of type Guid:
public virtual Guid Id { get; private set; }
And in your ClassMap you should map it like this:
Id(x => x.Id)
.Column("Id")
.GeneratedBy.GuidComb();
This will use the recommended comb algorithm to generate new guids.
or
Id(x => x.Id)
.Column("Id")
.GeneratedBy.Guid();
to genertae new Guids using System.Guid
or
Id(x => x.Id)
.Column("Id")
.GeneratedBy.GuidNative();
if you want to let the database generate the Guid for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With