Hi,
Being new to the EF, I'm really rather stuck on how to proceed with this set of issues. On the project I am currently working on, the entire site is heavily integrated with the EF model. At first, the access to the EF context was being controlled using an IOC bootstrapper. For operational reasons we were not able to use IOC. I removed this and used a model of individual instances of the context object where required. I started getting the following exception:
The type 'XXX' has been mapped more than once.
We came to the conclusion that the different instances of the context were causing this issue. I then abstracted the context object into a single static instance which was being accessed by each thread/page. I'm now getting one of several exceptions about transactions:
New transaction is not allowed because there are other threads running in the session.
The transaction operation cannot be performed because there are pending requests working on this transaction.
ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.
The last of these exceptions occurred on a load operation. I wasn't trying to save the context state back to the Db on the thread that failed. There was another thread performing such an operation however.
These exceptions are intermittent at best, but I have managed to get the site to go into a state where new connections were refused due to a transaction lock. Unfortunately I cannot find the exception details.
I guess my first question is, should the EF model be used from a static single instance? Also, is it possible to remove the need for transactions in EF? I've tried using a TransactionScope
object without success...
To be honest I'm a lot stuck here, and cannot understand why (what should be) fairly simple operations are causing such an issue...
Cheers, sicknote