代码之家  ›  专栏  ›  技术社区  ›  Michael Meadows

Fluent-NHibernate中的拦截属性设置

  •  1
  • Michael Meadows  · 技术社区  · 14 年前

    我是一个新的,能流利的国家,我认为应该是一个简单的问题。问题是我似乎找不到一个简单的答案。

    我有一个数据库列 nvarchar (SQL Server)。它应该映射到 System.Uri . 问题是 string 不会隐式转换为 Uri . 有没有办法“拦截”属性的设置以使用自定义逻辑?

    Map(x => x.WebAddress); // WebAddress in the DB is nvarchar, and it's a System.Uri in the model
    
    // would like to find something like what I have below
    Map(x => x.WebAddress).Intercept<string, Uri>(y => new Uri(y));
    

    我错过了什么?

    2 回复  |  直到 14 年前
        1
  •  1
  •   James Gregory    14 年前

    你应该使用 IUserType ,这是一个NHibernate特性,而不是流利的NHibernate。然后你会用 CustomType<YourUserType>()

    google搜索揭示了许多实现 IUserType型 接口,例如 http://www.martinwilley.com/net/code/nhibernate/usertype.html .

        2
  •  0
  •   ddc0660    14 年前

    我希望我能得到表扬,但我相信这个例子会完全符合你的期望。 http://swik.net/tag4sree/Hibernate+-+Objects/Implementing+custom+types+in+nHibernate/b3s2p