NHibernate中的列表vs集合vs包 [英] List vs Set vs Bag in NHibernate
问题描述
NHibernate映射文件中的列表,集合和包之间有什么区别?它们分别与.NET集合有什么关系?
What's the difference between a list, set and bag in the NHibernate mapping file? How does each relate to .NET collections?
推荐答案
NHibernate语义:
NHibernate semantics:
-
列表:实体的有序集合,允许重复.在代码中使用.NET
IList
.索引列将需要在NHibernate中进行映射.
List: Ordered collection of entities, duplicate allowed. Use a .NET
IList
in code. The index column will need to be mapped in NHibernate.
设置:唯一实体的无序集合,不允许重复.在代码中使用Iesi.Collection.ISet
(v4之前的NH)或System.Collections.Generic.ISet
(NH v4 +).覆盖GetHashCode
和Equals
以指示重复项的业务定义很重要.可以通过定义orderby或通过定义产生SortedSet
结果的比较器来进行排序.
Set: Unordered collection of unique entities, duplicates not allowed. Use Iesi.Collection.ISet
in code (NH prior to v4) or System.Collections.Generic.ISet
(NH v4+). It is important to override GetHashCode
and Equals
to indicate the business definition of duplicate. Can be sorted by defining an orderby or by defining a comparer resulting in a SortedSet
result.
包:实体的无序列表,允许重复.在代码中使用.NET ICollection<T>
.列表中的索引列未被NHibernate映射和引用.
Bag: Unordered list of entities, duplicates allowed. Use a .NET ICollection<T>
in code. The index column of the list is not mapped and not honored by NHibernate.
这篇关于NHibernate中的列表vs集合vs包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!