dotnet / EntityFramework.Docs

Documentation for Entity Framework Core and Entity Framework 6
https://docs.microsoft.com/ef/
Creative Commons Attribution 4.0 International
1.56k stars 1.94k forks source link

Primitive Collection Must Implement IList #4715

Open chapych opened 1 month ago

chapych commented 1 month ago

Type of issue

Missing information

Description

When adding primitive collections of IEnumerable returned by LINQ without casting them to List, Array, etc., the internal method Snapshot(IEnumerable source, ValueComparer elementComparer) is invoked after the SaveChanges() call, which checks if the input parameter is an IList.

In the scenario mentioned, this method throws an exception: "The type some_type cannot be used as a primitive collection because it is not an array and does not implement 'IList'. Collections of primitive types must be arrays or ordered lists."

It may be beneficial to note this peculiarity.

Page URL

https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-8.0/whatsnew#primitive-collections

Content source URL

https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/what-is-new/ef-core-8.0/whatsnew.md

Document Version Independent Id

97203c5d-fe52-b71e-dcb3-71c9492b4e04

Article author

@ajcvickers