我的实体除了其他属性之外还有Keyword属性,它是字符串列表的类型。
public virtual IList<string> Keywords { get; set; }
所以我试图通过代码方法尽可能简单地使用符合映射来映射这个属性,就像这样
Property(x => x.Keywords);
但我正在追踪异常
NHibernate.MappingException:无法确定以下类型: System.Collections.Generic.IList`1 [[System.String,mscorlib, 版本= 4.0.0.0,.....
答案 0 :(得分:1)
您可以将其映射到私人string
字段,然后在string.Split
获取者中使用Keywords
获取列表。
public class MyClass {
private string _keywords;
public virtual IEnumerable<string> Keywords {
get { return _keywords.Split(','); }
set { _keywords = string.Join(value, ","); }
}
}
我不熟悉NH使用的代码映射(我使用FluentNH)但你的映射可能是这样的:
Map("_keywords", map => {
map.Access(Access.Field);
// ...
});