使用流利的NHibernate和guid ID [英] working with Fluent NHibernate and guid ids

查看:419
本文介绍了使用流利的NHibernate和guid ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Fluent NHibernate 1.2,我们的主键是一个保存在 nvarchar(32)列中的guid,与Oracle 11gr2一起使用。

我们如何做这项工作? (做一个自动转换...)

先谢了,随机程序员...
$ b $ p

UPDATE:
忘记提及了,guid是没有破折号保存的...

解决方案

更新:



你将不得不实现你自己的IUserType来处理无暇的Guids。

你可以在这里阅读:
http://dotnet.dzone.com/articles/understanding-nhibernate-type



下面的细节现在与问题无关,但我会将其留在这里以供将来参考供人们查找。

使用Guids通常是

在你的实体中,Id的类型应该是Guid:

  public virtual Guid Id {get;私人设置} 

在你的ClassMap中,你应该这样映射它:

  Id(x => x.Id)
.Column(Id)
.GeneratedBy.GuidComb();

这将使用推荐的梳子算法来生成新的guid。



  Id(x => x.Id)
.Column(Id )
.GeneratedBy.Guid();

使用 System.Guid



  Id(x => x.Id) 
.Column(Id)
.GeneratedBy.GuidNative();

如果您想让数据库为您生成Guid。

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

解决方案

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.

这篇关于使用流利的NHibernate和guid ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆