Click here to Skip to main content
15,906,625 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Entity framework : a query is not working as expected Pin
Eddy Vluggen5-Apr-19 21:23
professionalEddy Vluggen5-Apr-19 21:23 
GeneralRe: Entity framework : a query is not working as expected Pin
Richard Deeming15-Apr-19 8:20
mveRichard Deeming15-Apr-19 8:20 
QuestionTrying to create generic object: SOLVED Pin
mo14923-Apr-19 6:53
mo14923-Apr-19 6:53 
AnswerRe: Trying to create generic object Pin
Richard Deeming3-Apr-19 7:39
mveRichard Deeming3-Apr-19 7:39 
QuestionVisual Studio 2010 project open in Visual Studio 2019 when run there is a error failed to sign Pin
Didier Cauberghe3-Apr-19 4:54
Didier Cauberghe3-Apr-19 4:54 
AnswerRe: Visual Studio 2010 project open in Visual Studio 2019 when run there is a error failed to sign Pin
Mycroft Holmes3-Apr-19 12:18
professionalMycroft Holmes3-Apr-19 12:18 
GeneralRe: Visual Studio 2010 project open in Visual Studio 2019 when run there is a error failed to sign Pin
Didier Cauberghe4-Apr-19 3:49
Didier Cauberghe4-Apr-19 3:49 
QuestionForce entity framework to load new data from database without disposing the context Pin
desanti2-Apr-19 3:21
desanti2-Apr-19 3:21 
Hello !
I'm using VB.net 2017 , Entity framework 6.
On my form I have loaded several entities and its childs.

Mylist=context.myobjs.Include("mychilds").Tolist.

Now , another user that use the same program from another computer , make some changes in some of the records and/or some childs. He save the data to database.

On my form I have a refresh button that execute the same query as above.
The problem is that when I press this button , on my list I have no updated values from database but the old values. It seems that that query does not read the database but use the data on local cache ( Why ???)

I know that disposing the context and creating a new one will resolve this problem , but I don't want to do this because on my forms I have other records from other entities that I have loaded . And if I recreate the context I need to load again all these but I don't want to do this because only records form 1 entity and its childs can be updated from other users as I described above.

Searching in internet , I've found 2 general methods doing this :

METHOD 1
For Each en As myobj In mylist
    context.Entry(en).Reload()
    For Each chld In en.mychilds
       context.Entry(chld).Reload()
     Next
Next


METHOD 2
For Each en As myobj In mylist
 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
Mylist=context.myobjs.Include("mychilds").Tolist


The problem is that both methods are very slow when mylist is very large.

Is there any other way ?

Thank you !
AnswerRe: Force entity framework to load new data from database without disposing the context Pin
Dave Kreskowiak2-Apr-19 4:23
mveDave Kreskowiak2-Apr-19 4:23 
GeneralRe: Force entity framework to load new data from database without disposing the context Pin
desanti2-Apr-19 7:40
desanti2-Apr-19 7:40 
GeneralRe: Force entity framework to load new data from database without disposing the context Pin
Dave Kreskowiak2-Apr-19 9:11
mveDave Kreskowiak2-Apr-19 9:11 
GeneralRe: Force entity framework to load new data from database without disposing the context Pin
desanti2-Apr-19 9:22
desanti2-Apr-19 9:22 
GeneralRe: Force entity framework to load new data from database without disposing the context Pin
Dave Kreskowiak2-Apr-19 11:24
mveDave Kreskowiak2-Apr-19 11:24 
GeneralRe: Force entity framework to load new data from database without disposing the context Pin
desanti3-Apr-19 5:01
desanti3-Apr-19 5:01 
GeneralRe: Force entity framework to load new data from database without disposing the context Pin
Dave Kreskowiak3-Apr-19 7:22
mveDave Kreskowiak3-Apr-19 7:22 
GeneralRe: Force entity framework to load new data from database without disposing the context Pin
desanti3-Apr-19 8:23
desanti3-Apr-19 8:23 
GeneralRe: Force entity framework to load new data from database without disposing the context Pin
Dave Kreskowiak3-Apr-19 8:57
mveDave Kreskowiak3-Apr-19 8:57 
GeneralRe: Force entity framework to load new data from database without disposing the context Pin
desanti3-Apr-19 9:40
desanti3-Apr-19 9:40 
GeneralRe: Force entity framework to load new data from database without disposing the context Pin
Dave Kreskowiak3-Apr-19 10:30
mveDave Kreskowiak3-Apr-19 10:30 
GeneralRe: Force entity framework to load new data from database without disposing the context Pin
desanti3-Apr-19 11:16
desanti3-Apr-19 11:16 
GeneralRe: Force entity framework to load new data from database without disposing the context Pin
desanti4-Apr-19 0:41
desanti4-Apr-19 0:41 
GeneralRe: Force entity framework to load new data from database without disposing the context Pin
Dave Kreskowiak4-Apr-19 5:49
mveDave Kreskowiak4-Apr-19 5:49 
GeneralRe: Force entity framework to load new data from database without disposing the context Pin
desanti4-Apr-19 6:18
desanti4-Apr-19 6:18 
GeneralRe: Force entity framework to load new data from database without disposing the context Pin
Dave Kreskowiak4-Apr-19 9:22
mveDave Kreskowiak4-Apr-19 9:22 
Questioni want to import a text file to datatable or something like that Pin
Member 142077921-Apr-19 4:41
Member 142077921-Apr-19 4:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.