使用自定义类型的id属性 [英] Using custom type for the id property

查看:136
本文介绍了使用自定义类型的id属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public class UserId 
{
public UserId(int id ){
//一些验证
}

公共覆盖字符串ToString(){}
}

public class User
{
public UserId Id {get; set;}
}

我可以配置nhibernate / fluentnhibernate使用该类。这个列是一个int。

解决方案

正如迭戈提到的,它不是一个好主意。 b $ b

  // UserMap 
Id(m => m.Id).CustomType< UserIdUserType>();

$ b class class UserIdUserType:IUserType {...}


I got the following classes:

public class UserId
{
    public UserId(int id){
        //some validation
    }

   public override string ToString() {}
}

public class User
{
    public UserId Id {get;set;}
}

How can I configure nhibernate/fluentnhibernate to use that class. The column is an int.

解决方案

as Diego mentioned it is not nessesaryly a good idea

// UserMap
Id(m => m.Id).CustomType<UserIdUserType>();


class UserIdUserType : IUserType { ... }

这篇关于使用自定义类型的id属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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