Does Entity Framework use a transaction for when you call SaveChanges on your context? Is there any way to turn off transactions completely, or have a certain entity opt out of a transaction?
AdventureWorksEntities db = new AdventureWorksEntities();
Product p1 = new Product();
// ...
Product p2 = new Product();
// set invalid data
db.Products.AddObject(p1);
db.Products.AddObject(p2);
// what happens when I call this - does it roll back everything?
// can i tell p2 not to participate in the transaction?
db.SaveChanges();
Yes, EF4 will create a new transaction if one does not already exist. See
http://msdn.microsoft.com/en-us/library/bb896325.aspx
No, there is no way to exempt a single entity from the transaction.
Not sure about your third question – about whether you can turn off transactions completely, but I’m guessing not based on the above excerpt.
I know this isn’t the answer you wanted to hear, but if you want P2 to save regardless of whether P1 succeeds, you would need to save P2 into a different object context.