c# - 为什么我的映射适用于 IList 而不是 LIst

标签 c# nhibernate

对于真正的大师的简单问题。 我花了很多时间思考如何在 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/

相关文章:

c# - VirtualAlloc 和 StdCall

c# - 如何从 C# ExpandoObject 按名称动态获取属性?

sql-server - NHibernate TooManyRowsAffectedException

performance - nhibernate - 归档记录

c# - 加法的十进制顺序影响结果

c# - 使用索引选择 XML 元素

c# - 在 .NET 核心中使用 Ajax 发布多个模型对象

带有 ResultSetTransformer 的 NHibernate future 查询

asp.net mvc nhibernate 单元测试

nhibernate - : Fluent nHibernate Exception 没有持久化