Help us, please :)
We use SessionManager, so default isolation level, as I understand, is ReadCommitted.
We call one method asynchronously by ajax request, there are two simultaneous request.
And we always get deadlock.
(code is simplified and "unrefactored")
public PhotoDto AddPhoto(int id, HttpPostedFileBase file)
var block = Session.Demand().Query.All<PhotoGalleryBlock>().FirstOrDefault(b => b.Id == id);
var photo = new Photo
FileName = "z"
//after uncommenting this line there is no deadlock on #1, but it happens on #2
var user = block.Page.Site.User;
var blocks = user.Site.PageSet.FirstOrDefault(p => p.IsMain).BlockSet;
var photoGalleryBlocks = blocks.OfType<PhotoGalleryBlock>();
foreach (var photoGalleryBlock in photoGalleryBlocks)
foreach (var photoi in photoGalleryBlock.PhotoSet)
var x = 5;
//DiskSpaces - Structure
user.DiskSpaces.PhotoGallery = 5;
return new PhotoDto(photo);
We get deadlock on foreach, trying to enumerate photoGalleryBlock.PhotoSet.
After uncommenting ### we get another deadlock on #2.
Actually, not on #2, but when transaction is completed, Sql Server throws an error
"deadlock on update User set [DiskSpaces.PhotoGallery] = 5"
Thanks in advance.
Mar 21 '12 at 14:01