0

Is it possible to adjust SQL Server Compact Edition version 4.0 connection parameters using Entity Framework in order to force Commit with a CommitMode.Immediate parameter as stated here https://stackoverflow.com/a/7342721/5529867 or https://stackoverflow.com/a/8687410/5529867 ?

  • SQL Server CE version: 4.0
  • EntityFramework: 6.1.3
  • EntityFramework.SQLServerCompact: 6.1.3
Community
  • 1
  • 1
iljon
  • 398
  • 2
  • 16

1 Answers1

1

No, this is only possible via raw ADO.NET (or you controlling the DbTransaction, possible with EF6 - https://msdn.microsoft.com/en-us/data/dn456843.aspx#existing )

 using (SqlCeConnection conn =
    new SqlCeConnection(@"Data Source=C:\data\AdventureWorks.sdf;"))
 {
     conn.Open();
     using (SqlCeTransaction tx = conn.BeginTransaction(IsolationLevel.ReadCommitted))
     {
         using (var context =  new BloggingContext(conn, contextOwnsConnection: false)) 
         { 
            context.Database.UseTransaction(tx); 
            var query =  context.Posts.Where(p => p.Blog.Rating >= 5); 
            foreach (var post in query) 
            { 
               post.Title += "[Cool Blog]"; 
            } 
            context.SaveChanges(); 
        }
        tx.Commit(CommitMode.Immediate); 
     }
}
ErikEJ
  • 40,951
  • 5
  • 75
  • 115
  • Thank you. Thus, I will adjust Flush-Interval parameter. – iljon Oct 12 '16 at 13:53
  • That will not force an immediate flush, I have updated my reply - also see my blog post here: http://erikej.blogspot.dk/2013/05/sql-server-compact-code-snippet-of-week_21.html – ErikEJ Oct 12 '16 at 16:14
  • Erik. I've just found that EF transaction commit is function without parameters (so Commit,Immediate) cannot be passed. I'm wonder how SQL CE commits transaction. Does it commit immediatelly or defer. – iljon Oct 14 '16 at 11:39
  • Combine the msdn link with my blog post code, and you can use commitmode.Immediate – ErikEJ Oct 14 '16 at 17:01