working with Fluent NHibernate and guid ids

吃可爱长大的小学妹 提交于 2019-12-05 11:30:33

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.

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