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

AddRange & Internal Snapshot Method Missing Info #4714

Closed chapych closed 1 month ago

chapych commented 1 month ago

Type of issue

Missing information

Description

The AddRange method accepts an IEnumerable as an argument, allowing for an IEnumerable returned by LINQ to serve as an input parameter and be passed to AddRange. However, after the SaveChanges() call, the internal method Snapshot(IEnumerable source, ValueComparer elementComparer) is invoked, which verifies if the input parameter is an IList.

In the scenario mentioned, this method throws an exception: "The type 'WhereSelectEnumerableIterator<ValueTuple<string, Category, bool>, Category>' 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 here: (https://learn.microsoft.com/en-us/ef/core/change-tracking/miscellaneous#addrange-updaterange-attachrange-and-removerange).

Page URL

https://learn.microsoft.com/en-us/ef/core/change-tracking/miscellaneous#addrange-updaterange-attachrange-and-removerange

Content source URL

https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/change-tracking/miscellaneous.md

Document Version Independent Id

c7456e25-0783-e271-bfee-3d1c443b2e90

Article author

@ajcvickers