HiveBrain v1.2.0
Get Started
← Back to all entries
gotchacsharpMinor

Why does DataContext.SubmitChanges() Exist?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
submitchangeswhyexistdatacontextdoes

Problem

I'm not sure if this goes here or on Stack Overflow, but I figure someone here might know it.

Why did the developers of LINQ decide that not only do you need

ctx.InsertOnSubmit(item);


but you also need

ctx.Items.SubmitChanges();


Did they do this so you could execute several queries on one trip to the database or am I missing something?

Solution

I'm not 100% sure about LINQ but i would say that the seperation is based on transaction control. You apply any number of updates, inserts or deletes. That are then held as a unit of work, then once you've finished your changes you simply commit them to the database as a single action or roll all of the changes back, maintaining the integrity of your database.

Context

StackExchange Database Administrators Q#3395, answer score: 3

Revisions (0)

No revisions yet.