c# - Entity framework incorrect data returned from linq select -


i'm new using entity framework, maybe i'm doing wrong, following code isn't working way i'd expect to:

productentities dbcustomerrefresh = new productentities(); int16 delay = 5000; while(true) {     var pendingfaults = (from f in dbcustomerrefresh.faults f.lrefreshstatus == 1 select f);     foreach(fault f in pendingfaults)     {         log.debugformat("initial refresh status fault {0} {1}", f.lfaultid.tostring(), f.lrefreshstatus.tostring());         f.lrefreshstatus = 2;         log.debugformat("changed refresh status fault: {0} {1}", f.lfaultid.tostring(),f.lrefreshstatus.tostring());     }     log.debugformat("saved {0} rows losch database",dbcustomerrefresh.savechanges().tostring());     thread.sleep(delay); } 

this works expected first time round loop, i.e. picks every row in db has lrefreshstatus set 1, changes 2 , prints debug.

i go database , manually change lrefreshstatus 1 given row. on next loop round, program picks status has changed again, initial values in variable wrong.

2015-07-30 09:27:17,137 [10] debug customerservice - initial refresh status fault 101380 1 2015-07-30 09:27:17,137 [10] debug customerservice - changed refresh status fault: 101380 2 2015-07-30 09:27:17,292 [10] debug customerservice - saved 1 rows product database 2015-07-30 09:27:22,297 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:27:27,304 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:27:32,313 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:27:37,318 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:27:42,327 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:27:47,336 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:27:52,341 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:27:57,346 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:28:02,356 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:28:07,361 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:28:12,366 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:28:17,371 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:28:22,378 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:28:27,384 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:28:32,390 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:28:37,396 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:28:42,405 [10] debug customerservice - initial refresh status fault 101380 2 2015-07-30 09:28:42,405 [10] debug customerservice - changed refresh status fault: 101380 2 2015-07-30 09:28:42,405 [10] debug customerservice - saved 0 rows product database 2015-07-30 09:28:47,410 [10] debug customerservice - initial refresh status fault 101380 2 2015-07-30 09:28:47,410 [10] debug customerservice - changed refresh status fault: 101380 2 2015-07-30 09:28:47,411 [10] debug customerservice - saved 0 rows product database 

its bizarre. select must pick value of fault status has changed 1 or wouldn't in pendingfaults variable, when go access property, set 2.

does not dispose of old f variable first time around, , give me again on second loop?

check this.

productentities dbcustomerrefresh = new productentities(); int16 delay = 5000; while(true) {     var pendingfaults = (from f in dbcustomerrefresh.faults f.lrefreshstatus == 1 select f);     foreach(fault f in pendingfaults)     {         log.debugformat("initial refresh status fault {0} {1}", f.lfaultid.tostring(), f.lrefreshstatus.tostring());         f.lrefreshstatus = 2;         log.debugformat("changed refresh status fault: {0} {1}", f.lfaultid.tostring(),f.lrefreshstatus.tostring()); log.debugformat("saved {0} rows losch database",dbcustomerrefresh.savechanges().tostring());     }  thread.sleep(delay); } 

see if makes difference.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -