Jonathan Wood
Jonathan Wood

Reputation: 67193

How to save changes after database connection has been closed

I have a question about Entity Framework and efficiency.

I have the need to load many rows of data, modify those rows, and then save those modifications.

I don't expect the number of rows to grow so large that storing them in memory will be a problem. However, in order to be able to save my changes, my understanding is that I must keep the database connection open while I make my changes in order to be able to save them. I don't want to hold the database connection open for that long.

Is there a way to load these records into memory, close the database connection, make my changes, and then reopen the connection to save those changes?

And if not, how else might one handle this situation efficiently?

Upvotes: 1

Views: 303

Answers (1)

David Browne - Microsoft
David Browne - Microsoft

Reputation: 89006

Is there a way to load these records into memory, close the database connection, make my changes, and then reopen the connection to save those changes?

Yes. See: Entity Framework Add and Attach and Entity States

Upvotes: 4

Related Questions