tags:

views:

71

answers:

2

Hello

I have an application with user and admin sections. If an admin updates data with the help of sql datasource then it's updated the database. However, when we retrieve data with linq query then it's showing its old value rather than the updated value.

After some time, the linq query automatically shows the correct value.

I think its caching the value, but I find myself helpless. Please help me with this.

A: 

Make sure that you're using your DataContext efficiently (ideally one per unit of work).

After each update, make sure you call DataContext.SubmitChanges(); to commit your changes back to the database.

Also be aware that any context you instanciate between your changes being added to another context and calling SubmitChanges() will not reflect those changes.

Justin Niessner
thanksWhen i am updating data with sql datasource only that time i get this problem otherwise its working fine.But it updates database.
Pankaj Mishra
but linq query showing old data
Pankaj Mishra
Make sure you're not creating the DataContext before updating the data with the Sql Datasouce (and if you're using Linq to retreive data, you should be using it to update data as well).
Justin Niessner
A: 

When you say

when we retrieve data with linq query

Do you mean you call your select methods again or are you using the current in memory objects?

In either case, you can always refresh an entity with :

Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, entity)
Mathlec