This question is related to a previous question of mine
That’s my current code
IEnumerable<Shape> Get()
{
while(//get implementation
yield return new Shape(//...
}
void Insert()
{
var actual = Get();
using (var db = new DataClassesDataContext())
{
db.Shapes.InsertAllOnSubmit(actual);
db.SubmitChanges();
}
}
I’m getting a memory overflow, since the IEnumerable is too big. How do I prevent it?
Try using InsertOnSubmit rather than InsertAllOnSubmit. And then commit at appropriate intervals, like Erich said.
Or, if you want to do it in batches of e.g. 5, try Handcraftsman’s or dtb’s solutions for getting IEnumerable’s of IEnumerable. E.g., with dtb’s Chunk: