Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't AutoDetectChangesEnabled set to false by default?

I was wondering why the AutoDetectChangesEnabled property on the DbContext is set to false by default.

I want to bulk insert into my context and as you might know turning the auto-detection to false brings way better performances.

I mean, if i know when to detect the changes to my context, is there any reason why i shouldn't set AutoDetectChangesEnabled to false?

like image 785
Francis Toupin Avatar asked Oct 05 '22 00:10

Francis Toupin


1 Answers

I think it is likely they wanted the more common and very useful behavior to work out of the box.

var mycontext = new DemoContext();
var myEntity = myContent.Thinhymybobs.find(akey);
myEntity.PropX = newvalue;
mycontext.saveChnages();

The update sent to the the DB is delta aware and the update set statement is used accordingly. So this is friendly on the DB.

When doing "bulk" operations on a DB, performance questions are normally a natural thought. So wondering about turning change off or indeed EVEN using tracking is a likely question i feel.

This article may interest you. State of an entry. http://msdn.microsoft.com/en-us/data/jj592676.aspx

like image 54
phil soady Avatar answered Oct 18 '22 23:10

phil soady