【发布时间】:2022-12-23 19:00:19
【问题描述】:
下面是 Visual Studio 的“Code First from database”向导生成的代码块:
public partial class Doc {
public Doc() {
Attachments = new HashSet<UploadedFile>();
}
public virtual ICollection<UploadedFile> Attachments { get; private set; }
// UploadedFile is a table with one of its foreign key column pointing to Doc's primary key column
}
正如所见,Visual Studio 在构造函数中将 Attachments 初始化为 HashSet。但我希望该集合保留插入顺序。
如果我将具体类型从 HashSet 更改为 List 是否安全?
此外,如果我想仍然保持“集合”性质(不重复插入)并同时保留插入顺序,我有什么选择?
【问题讨论】:
标签: .net collections set entity-framework-6