Problems with updating and reading in different contexts

Problems with updating and reading in different contexts

Postby na95mwn » Sat 22 Sep 2012 09:34

Unfortunately we use EF v1 still. The project I'm working on has been in active development since 2005 and since then we've been between 4 and 10 developers on it, so it's huge.

I have a WCF-service with one business component where I put my business logic and one dataaccess component where I put my Entity Framework model and methods against that. I want to seperate these to be able to mock my DAC-methods in unit tests of my business logic and also for reusability of the DAC-methods.

What I'd like to do is basically this. I want to call one method to update data and then another method to read the updated data. Below is the easiest example of this.

The problem is this. Sometimes, almost never, the data you read in one context will not have the update you just did in the other context.

As you all know the bugs that almost never appears are the worst.

Sure, it's easy enough to code around, ie make the DAC-methods more complex or move the EF-model to the BC, it but I want to keep my DAC-methods simple. They do one small thing and that's it.

Code: Select all

public Entity SaveEntity(Entity entity)
   var dac = new DataAccessComponent();

   // First save

   // Then read and return updated data
   return dac.ReadEntity(entity.key);   


public void UpdateEntity(Entity entity)
   using (context = new ....)
      // Do my updates

public Entity ReadEntity(Key key)
   using (context = new ....)
      var entity = context.Entity.First(x => x.Key == key);
      return entity;

Should I use a singleton context? But I've read about problems with that approach as well. Memory leaks and what have you. Or is there a way of making sure that the data gets committed to the database at once?
Posts: 3
Joined: Sat 12 Feb 2011 13:30
Location: SE

Re: Problems with updating and reading in different contexts

Postby Shalex » Mon 24 Sep 2012 11:34

We consider the code is correct and cannot currently suppose the possible reason of the issue. If you can localize the problem, please send us a small test project with the corresponding DDL/DML script to reproduce the issue in our environment.
Devart Team
Posts: 7393
Joined: Thu 14 Aug 2008 12:44

Return to dotConnect for Oracle