简体   繁体   English

是否可以配置 Entity Framework Core >= 7.0 以使用 List<t> 而不是哈希集<t>通过配置?</t></t>

[英]Is it possible to configure Entity Framework Core >= 7.0 to use List<T> instead of HashSet<T> by configuration?

Entity Framework >= 7.0 provides HashSet<T> as implementation to 1-n and mn associations (ie collections). Entity Framework >= 7.0 提供HashSet<T>作为1-nmn关联(即集合)的实现。 In my case, these associations are typed as ICollection<T> , and HashSet<T> doesn't work for me, because JSON PATCH ( RFC 6902 ) standard, it requires list data structure semantics (eg indexed collection, FIFO, etc.), when it comes to patching nested collections (ie arrays).在我的例子中,这些关联的类型为ICollection<T> ,而HashSet<T>对我不起作用,因为JSON PATCH ( RFC 6902 ) 标准,它需要列表数据结构语义(例如索引集合、FIFO 等。 ),当涉及到修补嵌套的 collections(即数组)时。

Therefore, I'd like to avoid a massive refactor which would involve typing associations as IList<T> , to leave DTOs agnostic to JSON PATCH implementation details.因此,我想避免涉及将关联键入为IList<T>的大规模重构,以使 DTO 与 JSON PATCH 实现细节无关。

Is it possible to configure Entity Framework Core to use List<T> instead of HashSet<T> by configuration (Code First)?是否可以通过配置(代码优先)将 Entity Framework Core 配置为使用List<T>而不是HashSet<T>

Have you already checked new interceptor - IMaterializationInterceptor ?您是否已经检查过新拦截器 - IMaterializationInterceptor https://devblogs.microsoft.com/do.net/announcing-ef7/#materialization-interception . https://devblogs.microsoft.com/do.net/announcing-ef7/#materialization-interception

Maybe it'll allow you to modify property after initialization?也许它会允许你在初始化后修改属性? Anyway, I'm not sure about navigation properties - but, you should give it a try and check it's possibilities.无论如何,我不确定导航属性 - 但是,您应该尝试一下并检查它的可能性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM