views:

33

answers:

2

Hi,

I'm not a real database expert, and i was wondering if you could tell me what kind of lock Sql server uses in combination with the entity framework in the following cases:

I read 40 records from a table, update them in code and call SaveChanges to the context

I read 1 record from a table, update it in code and call SaveChanges to the context

I create 1 new record (object) in code and call SaveChanges to the context

I create 40 new records (object) in code and call SaveChanges to the context

I also wondered, is it somehow possible to see which locks are used (set?) by Sql Server?

Michel

+1  A: 

I think this is difficult to answer, because it all depends on how you write the code. Entity framework doesn't do the actual SELECT-statement before you use any data. For instance: Dim v = (From a in Something Select a) For Each b in v Next

In this code block, the actual "SELECT * FROM Something" isn't executed on the SQL Server before it comes to the "For Each" line. The best answer I can give you is to test it yourself by looking at sys.dm_tran_locks which returns all locks.

Vidar Nordnes
+1  A: 

The locking depends on how you have SQL Server configured, not on the EF. You monitor locking using the dynamic management views.

Craig Stuntz
oh, ok. I thought that EF maybe would pass some locking hint or demand to Sql Server.
Michel