Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# EF First
Hello,
 
I have this strange problem:
 
You have a database with these rows:
Table: Letter
 
Id=1,Name="A"
Id=1,Name="B"
Id=1,Name="C"
Now you make the query
var q= (from l in context.Letter where l="A" select l);
g.Load();
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
g.Load();
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 23:56pm
Edited 19-Sep-12 0:51am
v3

1 solution

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

Solution 1

  Permalink  
Comments
Js. Urb. at 19-Sep-12 5:41am
   
Hello,
 
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.
 
Thanks,
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 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,327
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,920


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 19 Sep 2012
Copyright © CodeProject, 1999-2014
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