Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

EntityFramework returning cached data Expand / Collapse
Posted Sunday, March 23, 2014 11:59 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Sunday, March 23, 2014 11:46 AM
Points: 87, Visits: 155
I have a datagridview bound to a table that is part of an Entity Framework model. A user can edit data in the datagridview and save the changes back to SQL. But, there is a stored procedure that can also change the data, in SQL, not in the datagridview. When I try to "refresh" the datagridview the linq query always returned the older cached data. Here's the code that I have tried using to force EF to pull retrieve new data:

// now refresh the maintenance datagridview data source
using (var context = new spdwEntities())
var maintData =
from o in spdwContext.MR_EquipmentCheck
where o.ProdDate == editDate
orderby o.Caster, o.Strand
select o;
mnt_DGV.DataSource = maintData;

I've seen a number of posts suggesting this method, but it didn't work for me. When I debug, I can see that the SQL table has the updated data in it, but when this snippet of code runs, maintData has the old data in it.

I've had this problem with a couple of other datagridviews and I solved it with a really ugly work-around (which I refuse to initial). I need to clean all of them up. So, I'd really appreciate some help.


Post #1553831
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse