Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>you need to manually lock the table via SQL. i found this post, i think its what you need. but its not that satisfying..</p> <p><a href="https://stackoverflow.com/questions/1625784/locking-a-table-with-a-select-in-entity-framework">Locking a table with a select in Entity Framework</a></p> <p>EDIT:</p> <pre><code> using (var ts = new TransactionScope()) { var db = new Db(); var asd = from x in db.MyTable where x.Id == 1 select x; asd.First().Name = "test2"; db.SaveChanges(); // if you're here with the debugger the table is locked } // and now its unlocked and you can do a select again internal class Db : DbContext { public Db() { Database.DefaultConnectionFactory = new SqlConnectionFactory(); //Database.SetInitializer(new DropCreateDatabaseIfModelChanges&lt;Db&gt;()); Database.Connection.ConnectionString = "yourconnectionstring;"; } public DbSet&lt;MyTable&gt; MyTable { get; set; } } internal class MyTable { public int Id { get; set; } public string Name { get; set; } public DateTime MyTime { get; set; } } </code></pre> <p>EDIT2:</p> <p>i played around with EF and TransactionScope a little here are my results:</p> <pre><code>using (var ts = new TransactionScope()) { var db = new Db(); var asd = from x in db.MyTable where x.Id == 1 select x; db.SaveChanges(); // you still can fire selects in the studio asd.First().Name = "test2"; // now a change is made but not written to the transaction db.SaveChanges(); // after this call you can't fire selects in the management studio, the table is locked var asd2 = from x in db.MyTable where x.Id == 1 select x; asd2.First().Name = "test3"; db.SaveChanges(); // the table still is locked } // now you can do selects again, the table is unlocked </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload