2

在我们的解决方案中,当映射枚举时,不是简单地保存整数或文本描述,而是使用自定义IUserType来根据数据库表解析文本描述并检索适当的 ID。(这些值在应用程序启动时缓存以加快速度)

这对于单个 Enum 属性非常有效。映射代码(使用映射覆盖)看起来像这样......

POCO:

  public class Connection
  {
      // Other properties omitted
      public Protocol Protocol { get; set; }
  }

映射覆盖:

  mapping.Map(map => map.Protocol, "ProtocolID")
         .CustomType<GenericEnumUserType<Protocol>>();

当我有要映射的枚举列表时,就会出现我的问题。例如...

POCO:

  public class Credential
  {
      // Other properties omitted
      public ICollection<Protocol> Protocols { get; set; }
  }

我的研究(此处此处)表明映射应类似于以下内容:

  mapping.HasMany(x => x.Protocols)
         .Table("TABLE")
         .KeyColumn("COLUMN")
         .Component(component =>
                   {
                           //MAP YOUR CUSTOM TYPE HERE
                   })
         .Cascade.None()
         .KeyNullable()
         .Not.LazyLoad();

...但我无法弄清楚如何CustomType在该MAP YOUR CUSTOM TYPE HERE部分中连接。

另一方面,这个 SO 线程建议CustomType不适用于集合 - 但是该特定评论的日期为 2009 年,所以我希望从那时起有所改变。

这种类型的映射是否可能(如果可以,我错过了什么)还是我需要开始寻找最合适的解决方法?

干杯。

4

0 回答 0