MikaelEliasson / EntityFramework.Utilities

Provides extensions for EntityFramework that doesn't exist out of the box like delete and update by query and bulk inserts
443 stars 176 forks source link

Stop multiple enumeration of items #96

Open smithkl42 opened 8 years ago

smithkl42 commented 8 years ago

The code for bulk insertion currently iterates through the items twice: once when counting them to determine batch size, and once when actually inserting them. This is more-or-less harmless for a List<T> datasource, but is problematic when you're generating items (as I was) via a yield return kind of construct. I don't think that there's any problem with having a batch size larger than the actual batch, so the simplest way to handle it was just to stop the first (counting) iteration.