Click here to Skip to main content
11,803,019 members (77,356 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# entity-framework

I have this strange problem:

You have a database with these rows:
Table: Letter
Now you make the query
var q= (from l in context.Letter where l="A" select l);
Now in context.Local yo have only one row (the first one)

If you go to database and remove or delete or add files, the Local refresh accordingly (you must use Load() and Refresh() between changes).

But in this case it does not work, see it:

You go to database and change "A" to "B" and repeat the query
The entity changes his value to "B" so it must been removed from Local but it stills alive in Local (count==1) when the local must have 0 elements (count==0)

Any idea?
Posted 18-Sep-12 22:56pm
Edited 18-Sep-12 23:51pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Js. Urb. at 19-Sep-12 5:41am

I appreciate your help, but i am already using Refresh(), the problem is that in the scenario i expose Refresh()/Load() does not work, you can try it if you wish.

Zoltán Zörgő at 19-Sep-12 6:51am
With load, you just force execution of the deferred query. But with refresh you force the context to reload data. Have you really tried that also? Since I had the same problem, and calling refresh on the context solved it.
Js. Urb. at 19-Sep-12 7:21am
It works in the scenarios i talk about (add, delete, edit,...) but try the case i talk above, one Entity that is changed after initial execution and does not mismatch must dissapear but is not the case, keep in mind that i am using CodeFirst casting DbContext to ObjectContext to use Refresh()
Js. Urb. at 19-Sep-12 10:07am
I think that's because DBQuery encapsulates a ObjectQuey with MergeOption set to AppendOnly and it does not seem possible to set to OverwriteChanges...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 KrunalRohit 356
1 OriginalGriff 335
2 CPallini 270
3 F-ES Sitecore 270
4 Sergey Alexandrovich Kryukov 234
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,735
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 19 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100