0

I have two web-applications (Frontend and Backend).

Applications

Both applications share the same database.

On development environment (debug) I launch both simultaneously. Two Application Run

When debugging, if I change value of any field in BackEnd, on FrontEnd changes are not applied. In the database values ​​are changed. (ie Update passed, SELECT from Management Studio gives the correct data)

My guess is that on FrontEnd EF stores a local copy of the data.

Changes appear (on FrontEnd) only when I restarted debug.

A code example for FrontEnd:

using (company_unitEntities _fc = new company_unitEntities())
{
    var ff = _fc.agency_tamplates_d.ToList();
}

Interesting Fact:

When I add AsNoTracking method to data load, and watched Prifiler, I discovered that 'SELECT` queries arrive at the server, but the changes do not appear.

using (company_unitEntities _fc = new company_unitEntities())
{
    var ff = _fc.agency_tamplates_d.AsNoTracking().ToList();
}

Profiler

What could be the reason for such behavior EF?


I use: ASP.NET MVC 4, Entity Framework

Thank you!

UPD: FrontEnd and BackEnd use different Entity Data Model.

Anderson Matos
  • 2,996
  • 1
  • 21
  • 33
dima_horror
  • 1,395
  • 11
  • 20
  • Unless you are doing edit and continue I'm not sure why you think code changes would automatically be applied. Naturally you have to recompile and restart. – Greg Ennis Jan 09 '14 at 14:07
  • Recompile every time I want to retrieve data from the database? You must be joking. – dima_horror Jan 09 '14 at 14:09
  • Sorry, I thought you were making table/schema changes, not just data changes. I misread. Yes, EF does cache queries – Greg Ennis Jan 09 '14 at 14:11
  • How is it possible to worked simultaneously two applications with the same database using the EF? Disable cache? Use one Entity Data Model? Thanks.. – dima_horror Jan 09 '14 at 14:15
  • I had a similar issue, you can look at MergeOption.OverwriteChanges when you retrieve the data. Take a look at this: http://stackoverflow.com/questions/6126845/refreshing-data-using-entity-framework – lopezbertoni Jan 09 '14 at 14:19
  • EF has a complex cache strategy for better performance but that might drive you crazy on some data changes. Basically, inside your `using` closure EF will fall back to cache unless there is none. For that, every call should be performed with `AsNoTracking`. Sometimes that will crash your code and you'll have to use the `MergeOption`, as pointed out before. To check if this is a cache issue, create a new context (outside your `using` statement) and try fetch the same data with the `AsNoTracking` option. If it does retrieve data correctly, you'll have to modify your using statement... – Anderson Matos Jan 09 '14 at 15:35

0 Answers0