流畅的 NHibernate 和带有索引器映射的类
如何使用流畅的映射将 AttributeSet 类与 Fluent NHibernate 进行映射
public class AttributeSet : DictionaryBase
{
private readonly Dictionary<string, object> _cache;
public AttributeSet()
{
_cache = new Dictionary<string, object>();
}
public object this[string index]
{
get
{
return _cache[index];
}
set
{
_cache[index] = value;
}
}
}
public class Entity
{
protected Entity()
{
Attributes = new AttributeSet();
}
public virtual int Id { get; set; }
public virtual string Label { get; set; }
public virtual string Description { get; set; }
public virtual DateTime CreatedDate { get; set; }
public virtual AttributeSet Attributes { get; set; }
}
How can I map the class AttributeSet with Fluent NHibernate using a fluent mapping
public class AttributeSet : DictionaryBase
{
private readonly Dictionary<string, object> _cache;
public AttributeSet()
{
_cache = new Dictionary<string, object>();
}
public object this[string index]
{
get
{
return _cache[index];
}
set
{
_cache[index] = value;
}
}
}
public class Entity
{
protected Entity()
{
Attributes = new AttributeSet();
}
public virtual int Id { get; set; }
public virtual string Label { get; set; }
public virtual string Description { get; set; }
public virtual DateTime CreatedDate { get; set; }
public virtual AttributeSet Attributes { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为没有办法直接映射索引器,但您可以公开底层字典类型并映射它。
如果您不想将字典公开为公共,则可以将其映射为私有属性,如此处所述。要映射字典,请参阅此处。
一个例子可能是
映射字典中的对象类型可能很有趣,我不知道 NHibernate 是否能够将其直接转换为底层数据库类型。
I don't think there's a way to map your indexer directly, but you can expose the underlying dictionary type and map that instead.
If you don't want to expose the dictionary as public you can map it as a private property instead as explained here. For mapping a dictionary, see here.
An example might be
Mapping the object type in the dictionary might be interesting, I don't know if NHibernate will be able to translate it directly to an underlying database type.