Fluent NHibernate Automap不考虑IList<;T>;作为索引的集合
我正在使用automap映射域模型(简化版):Fluent NHibernate Automap不考虑IList<;T>;作为索引的集合,nhibernate,fluent-nhibernate,nhibernate-mapping,Nhibernate,Fluent Nhibernate,Nhibernate Mapping,我正在使用automap映射域模型(简化版): 公共类AppUser:实体 { [必需] 公共虚拟字符串昵称{get;set;} [必需] [数据类型(数据类型.密码)] 公共虚拟字符串密钥{get;set;} [必需] [数据类型(数据类型.电子邮件地址)] 公共虚拟字符串EmailAddress{get;set;} 公共虚拟IList首选项说明{get;set;} } 公共类首选项描述:实体 { 公共虚拟AppUser AppUser{get;set;} 公共虚拟字符串内容{get;set;
公共类AppUser:实体
{
[必需]
公共虚拟字符串昵称{get;set;}
[必需]
[数据类型(数据类型.密码)]
公共虚拟字符串密钥{get;set;}
[必需]
[数据类型(数据类型.电子邮件地址)]
公共虚拟字符串EmailAddress{get;set;}
公共虚拟IList首选项说明{get;set;}
}
公共类首选项描述:实体
{
公共虚拟AppUser AppUser{get;set;}
公共虚拟字符串内容{get;set;}
}
PreferencesDescriptions集合映射为IList,索引集合也映射为IList(当我需要标准的未索引集合时,我使用ICollection)
事实上,fluent nhibernate的automap工具将我的域模型映射为未索引的集合(因此SchemaExport生成的DDL中没有“位置”属性)
?我如何在不重写这种情况的情况下实现它?我的意思是,我如何使Fluent nhibernate的automap始终为IList创建索引集合,但不为ICollection创建索引集合IList不是索引集合。您可以通过索引访问IList中的元素,但它们的位置不存储在数据库中。您不能按索引访问ICollection(不使用扩展方法),但它有一个AddAt方法,可以在索引处将对象添加到集合中
如果需要在集合中存储对象位置,请将其映射为等同于IDictionary的。我假设自动映射将对IDictionary集合类型使用映射。在NHibernate中,您可以将索引集合映射到IList。无论如何,谢谢你。
public class AppUser : Entity
{
[Required]
public virtual string NickName { get; set; }
[Required]
[DataType(DataType.Password)]
public virtual string PassKey { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
public virtual string EmailAddress { get; set; }
public virtual IList<PreferencesDescription> PreferencesDescriptions { get; set; }
}
public class PreferencesDescription : Entity
{
public virtual AppUser AppUser { get; set; }
public virtual string Content{ get; set; }
}