Nhibernate ASP.NET MVC3+;ActiveRecord+;有许多+;词典

Nhibernate ASP.NET MVC3+;ActiveRecord+;有许多+;词典,nhibernate,dictionary,castle-activerecord,Nhibernate,Dictionary,Castle Activerecord,我正在尝试为我的一个ASP.NETMVC模型建立一个字典数据结构。本质上,我想要一个设置的散列图作为键值对。我的代码类似于: [ActiveRecord] public class Blog extends ActiveRecordBase<Blog> { [Property] public IDictionary<string, string> Settings { get; set; } } 我尝试添加一个虚拟索引(因为我不清楚如何使用ActiveRecor

我正在尝试为我的一个ASP.NETMVC模型建立一个字典数据结构。本质上,我想要一个设置的散列图作为键值对。我的代码类似于:

[ActiveRecord]
public class Blog extends ActiveRecordBase<Blog> {
  [Property]
  public IDictionary<string, string> Settings { get; set; }
}
我尝试添加一个虚拟索引(因为我不清楚如何使用ActiveRecord添加索引),如下所示:

  [Property(Index="")]
  public IDictionary<string, string> Settings { get; set; }

因此,我的问题是:在不创建新类来封装键值对的情况下,使用字符串键/值对字典作为单个字段来设置ActiveRecord模型需要什么(代码/数据库方面)?

您需要一个
IUserType
。a
IUserType
与您需要的非常相似


然后使用
[property]
属性的
ColumnType
属性来引用您的
IUserType

的完全限定类型名称,只是为了清楚起见,您希望将整个字典存储在单个字段中?@Mauricio correct;这是我的理想设计,如果可能的话,我想实现它。这看起来和创建自己的键值对类一样麻烦(如果不是更麻烦的话)。@ashes999如果要将整个字典存储在单个字段中,这是唯一的方法。如果您编写自己的键值对类,您将不得不使用另一个表或单独的字段;但从我的角度来看,这需要为一些相对简单和自动的东西编写很多代码。我想我会选择一张定制的桌子:/
  [Property(Index="")]
  public IDictionary<string, string> Settings { get; set; }
ActiveRecord tried to infer details about the relation Blog.Settings but it could not find information about the specified target type System.String. If you have mapped a Collection or Dictionary of value types, please make sure you have specified the Table property