Tuesday 19 June 2012

EF: New transaction is not allowed because there are other threads running in the session.

Having quite a few issues after I updated a key project to Entity Framework 4.0 (EF4), it seems that a search using a read closely followed by a write update the EF context. After much searching and fiddling

I came across a blog where they added a ToList() at the end of a query.

This seemed to work as it closed the transaction directly after a read.

This is very odd and did not happen in previous versions of EF.


Example below in the change in repository Helper

 FROM THIS

 public static List GetAll()
 {
           var results = RepositoryRole.GetAll(); 
            return results.ToList(); 
 } 


 TO THIS

 public static List GetAll() 
 { 
      var results = RepositoryRole.GetAll().ToList();
      return results;
 }


p.s. I have lost the reference post that gave me the answer, opps sorry if it was your post, I'll add it if I find it again.

No comments:

Post a Comment

Comments are welcome, but are moderated and may take a wee while before shown.