I'm using vb.net 2017 , Entity Framework 6 and sql server 2018R2. I have a table , TB1(id , name , value1) I get the data :
myquery=(From t in context.tb1s select t).tolist
Now , myquery has a record with these values : name=Name1 , value1=5
Another user that run the same program on another PC , make a change on this record on database , value1=10. He save the changes on database.
On my form i have a button "Refresh" that execute again my first query :
myquery=(From t in context.tb1s select t).tolist
But on that record , the value1 is still 5 and does not get the updated value. I have no problems when the other user create a new record , or delete an existing record. When i press my Refresh button all these changes are reflected. But when a record is updated , i have always the old values.
How can i resolve this problem WITHOUT DISPOSING THE CONTEXT ?
Thank you !
EDIT I've found 2 general methods to resolve this without disposing the context ( to refresh entity and its child from database with new values )
METHOD 1
For Each en As tb1 In tb1collection
context.Entry(en).Reload()
For Each chld In en.mychilds
context.Entry(chld).Reload()
Next
Next
METHOD 2
For Each en As tb1 In tb1collection
For i= en.mychilds.count-1 to 0 step -1
context.Entry(en.mychilds(i)).State = EntityState.Detached
Next
context.Entry(en).State = EntityState.Detached
Next
context.tb1s.Include("mychilds").Load
THE PROBLEM IS THAT BOTH METHODS ARE VERY SLOW WHEN THE COLLECTION OF ENTITIES TO BE REFRESHED IS VERY LARGE. WHAT CAN I DO ?