working with Fluent NHibernate and guid ids

断了今生、忘了曾经 提交于 2020-01-02 05:08:06

问题


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 ...


回答1:


Update:

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.

Using Guids "normally"

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.



来源:https://stackoverflow.com/questions/6408714/working-with-fluent-nhibernate-and-guid-ids

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!