对于真正的大师的简单问题。
我花了很多时间思考如何在 nhib 中映射集合。通过代码映射,我现在有一个问题,为什么我的映射适用于 IList
类型的集合,而不适用于 List
?
这是代码
public class Account {
private IList<Term> Terms; // When I use List it does not work
public Account()
{
Terms = new List<Terms>();
}
public virtual IList<Term> Terms // When I use List it does not work
{
get { return _Terms; }
set
{ if (_Terms == value) return;
_Terms = value;
}
}
}
AccountMap.cs(一个帐户有多个术语)
Bag(x => x.Terms,
m =>{},
x => x.OneToMany()
);
最佳答案
文档说:6.1. Persistent Collections :
NHibernate requires that persistent collection-valued fields be declared as an interface type
以及支持的接口(interface)列表:
The actual interface might be
Iesi.Collections.ISet
,System.Collections.ICollection
,System.Collections.IList
,System.Collections.IDictionary
,System.Collections.Generic.ICollection<T>
,System.Collections.Generic.IList<T>
,System.Collections.Generic.IDictionary<K, V>
,Iesi.Collections.Generic.ISet<T>
或者...任何你喜欢的东西! (其中“任何你喜欢的”意味着你必须编写 NHibernate.UserType.IUserCollectionType
的实现。)
关于c# - 为什么我的映射适用于 IList 而不是 LIst,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14296182/