Entity Framework Performance With Simple Insert is terrible <p>I am using EF 5 with code first against mySQL 5.5.25 with the 6.5.6 mySQL DotNet connector (However it is not the connector as the DevArt connector exhibits the same performance) and have an entity as follows:</p> <pre><code>public class SocialMediaEventEntity { public virtual int Id { get; set; } //PK public virtual DateTime Date{ get; set; } public virtual string ProvIdType{ get; set; } public virtual string ProviderId{ get; set; } public virtual int Rendered{ get; set; } public virtual int Sent{ get; set; } public virtual decimal UserId { get; set; } public virtual string UserName { get; set; } public virtual string UserScreenName { get; set; } public virtual string UserDescription { get; set; } public virtual ICollection&lt;HistoryEntity&gt; Messages { get; set; } } </code></pre> <p>It uses the following Code First to configure the keys etc.</p> <pre><code> HasKey(entity =&gt; entity.Id); Property(entity =&gt; entity.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).IsRequired(); </code></pre> <p>Ultimately I am adding a single row to this table via:</p> <pre><code> var socialEvent = new SocialMediaEventEntity() { Date = ADate, ProviderId = AProviderId, ProvIdType = AProviderIdType, Rendered = ARendered, Sent = ASent, UserId = AUserId, UserName = AUserName ?? string.Empty, UserScreenName = AUserScreenName ?? string.Empty, UserDescription = AUserDescription ?? string.Empty, Messages = new List&lt;HistoryEntity&gt;() }; MyDBContext.SocialMediaEvents.Add(socialEvent); </code></pre> <p>Under the skin this generates the expected SQL of:</p> <pre><code>INSERT INTO tblSocialMediaEvents(`Date`, ProvIdType, ProviderId, Rendered, Sent, UserId, UserName, UserScreenName, UserDescription) VALUES ('2013-03-25 14:26:30', 'Twitter', '316028289447763968', 0, 0, 280310495, 'ChuBbyBhu', 'Komang Trinda Dewi', 'Always smile,,,but no crazy..:D\r All must be beautiful in its time' </code></pre> <p>Now the INSERT statement when profiled on my machine is very quick in the order of ~1ms, but the call to:</p> <pre><code>MyDBContext.SaveChanges(); </code></pre> <p>Takes anything from ~20 to ~40ms and occasionally > 100ms. </p> <p><img src="https://i.stack.imgur.com/cnDxf.png" alt="enter image description here"></p> <p>When I profile the code I see that its actually the transaction commit that is taking most of the time. However this is not the case when I do exactly the same SQL within a transaction into mySQL.</p> <p>So my questions are:</p> <ul> <li>How do I improve performance of this code? Aside from call SaveChanges() less often?</li> <li>Why is the transaction commit taking so much longer than when it is done executing the same code in a mySQL client tool like HeidiSQL?</li> </ul> <p>Appreciate any help and pointers.</p> <blockquote> <p>Edit: I have used the exact same code against SQL Server 2008 Express and performance is spectacular. Generally INSERTS are &lt; ~1ms and the SaveChanges ~1ms. Naturally I would expect M$ products to be fast, but I am stuck with mySQL and cannot change. So is there anything I can do?</p> </blockquote>