Skip to main content

Microsoft Silverlight

Unanswered Question Direction on this (2 things) delayed update and refresh?RSS Feed

(0)

tkousek
tkousek

Member

Member

15 points

40 Posts

Direction on this (2 things) delayed update and refresh?

Hello

Was wondering if anyone can point me in the right direction on this.     I have not had to deal with this in RIA until today and was hoping someone could kick start me in the right direction.

Problem 1:

 I have a situation.   TableA has row1 with a column called status with the value of A.    I have row1 loaded in my client context and displayed in a datagrid in silverlight.   There is a server process that updates row1's status on the server to I.  When I try and reload the data from my client, it won't grab the new value of status even though the value of status (thru Toad) reports that it is I.  Thru breakpoints on the server side in the DomainServer, I am still seeing the value of A.

 How can I force a "refresh" on the server side.  I even tried calling Load with the MergeOption.KeepChanges which the ria services manual says it will grab the new values from the db.  But even that is not loading in I for the status.  

Now if I completely recreate my context again from the client (ie, call new() on it) and force a reload, it will grab the new values.   I'm hoping not to have to do that. 

This is what the domain service call method looks like and it's ot picking up the changes that another process made to the DB.

this.Context.Refresh(System.Data.Objects.RefreshMode.StoreWins, Context.TableA);

return this.Context.TableA;

I saw this link

http://forums.silverlight.net/forums/p/129057/289275.aspx#289275

but is there anyway to do this without having to recreate the context? 

 

Problem 2:

Maybe this is MYSQL and not entityframework/RIA.  

When I call Update, I notice it takes upwards to 5-10 seconds "after update" succeeeds before I see the new value.   So in toad, I can refresh for up to 10 seconds (after an update thru RIA) and then I'll finally see the new value.   How can I get the update to immediately sync to the database.   The update will return successfully/immediately back to the client and will show the new value but I suspect it's cached in-memory and not yet flushed to disk.

I'm using mysql 5.1.

 

 thanks in advance.

tkousek
tkousek

Member

Member

15 points

40 Posts

Re: Direction on this (2 things) delayed update and refresh?

Not sure I like this solution but it seems to be working.   Please tell me if this seems problematic.

For problem #2, I called

this.Context.Refresh(System.Data.Objects.RefreshMode.ClientWins, Context.TableA);

right before SaveChanges() in the DomainService and now it seems like the value is instantly reflected in Toad for mysql when I examine the values of the status in the row.   However that still does not help me with problem 1 as....

I have a WCF service that updates the status and I overrode SaveChanges() to call Refresh prior to the base.SaveChanges.

 For problem #1, since I *know* the value that is to be updated, I updated that value locally within the context and called NotifyPropertyChange to display the new status (in the datagrid) but only after the WCF service returns success.

Basically, I'm calling the WCF service to send out an email notifcation and it will update the DB behind the scenes to indicate that the email was sent out.   That service is doing what problem #2 aboved fixed and it's using a different context.    On the client, if I get a success from the service, then I know it updated the status.   So I update the status locally.   Later on when submitchanges is called, I get a concurrency exception (as a result of updating the value on the client side and not reloading from the server because I can't seem to get the changes refreshed within the same data context instance) and ended up implementing the resolve(...) on in the DomainService to go ahead with the changes and avoid the Concurrency exception from being returned.

This seems to be working but if anyone else knows how to refresh immediate changes within the same instance of the context without creating a new context, please let me know as I would be greatly appreciative!!

thanks

xusun
xusun

Participant

Participant

1069 points

179 Posts

Microsoft

Re: Direction on this (2 things) delayed update and refresh?

For your problem #1:

1. Are you using any static ObjectDataContext in your server project?  Otherwise, the server side should be stateless, meaning it should create a new DataContext in the server each time when it tries to load. 

2. In the client you should trigger a Load operation, with MergeOption of Merge or Refresh.  You should not use KeepChanges.  KeepChanges  means "Keep the client Changes", and it will discard server values.

 

Thanks,
Xun Sun - MSFT

tkousek
tkousek

Member

Member

15 points

40 Posts

Re: Direction on this (2 things) delayed update and refresh?

Hi

for #1, I am not using any statics.  

for #2, I tried

OverwriteCurrentValues   on the MergeOptions in the Load and it still is not pulling in the latest.   Just for verification, I tried all 3:

KeepChanges (as you mentioned this would not work),

KeepCurrentValues and OverwriteCurrentValues

On a load of the same context (that the initial Load was called on) 

All 3 without any luck on the same context :-(     If I use a different context, it will work.

What would be the best way to "merge" changes from a different context (call it B) into the same context (A where A was initially loaded) without having A report that a change occurred in the ChangeSet?   What I could do is refresh from a different context and merge back into the original context A.   Reason I don't want to recreate context A is that I preloaded it with about 10 tables (a certain entity has a primary table and 9 child tables).   I would just like to refresh the one particular table without having to reload all of the other tables again.

 thanks

xusun
xusun

Participant

Participant

1069 points

179 Posts

Microsoft

Re: Re: Direction on this (2 things) delayed update and refresh?

Can you post the code that you "force" it to reload?  I'd like to see the client side code.

Also, could you explain how you verify that the data is not updated?  I just tried and it could update the new value if I bind the EntitySet to a DataGrid.

Thanks,
Xun Sun - MSFT

tkousek
tkousek

Member

Member

15 points

40 Posts

Re: Re: Direction on this (2 things) delayed update and refresh?

Hi

The client code is as follows.   *After* another process in a WCF service updates the status in the table under a different context instance, the client receives the asynchronous completed event from the WCF service.   I have Toad for mysql up and I am able to open up that table and see that the status of the row was changed to "R".   On the client in it's context, the status is still "A".   Then I issue the following code below and I set a breakpoint in the the "Loaded" method below and examine the value of the status in the EventFormContext, it still is set to "A".   I have verified (thru breakpoints) that the domainservice "GetEventInstructorByEventId" is being called so it is making the round trip.   The only way it seems I can refresh this is to recreate the EventFormContext which is a pain because I may have many changes pending in there that I'm not ready to "commit" (as the user can "cancel" those changes too).   All I want to do is get the "new" values from that table and have them reflected in my already existing EventFormContext.

thanks.

LoadOperation<event_instructor> op = EventFormContext.Load(EventFormContext.GetEventInstructorByEventIdQuery(ei.Event_Id),

EventInstructorDataLoaded, MergeOption.OverwriteCurrentValues);

xusun
xusun

Participant

Participant

1069 points

179 Posts

Microsoft

Re: Re: Direction on this (2 things) delayed update and refresh?

The load operation looks good to me. 

Can you verify one more thing.  In your server project, can you set a breakpoint in your GetEventInstructorByEventIdQuery(...) method, and verify that it indeed returns the updated value, "R", but not the old value?

Thanks,
Xun Sun - MSFT

tkousek
tkousek

Member

Member

15 points

40 Posts

Re: Re: Direction on this (2 things) delayed update and refresh?

Hi

 Now this is interesting.   Iterating thru the collection on the server yields that the status is "R".   I should have also mentioned that I have a foreign key association between event_instructor and event_instructor_status.   So basically, I'm looking at event_instructor.event_instructor_status.

 On the loadcomplete back on the client side, I'm looking at  op.AllEntities which is 3 (one for the event_instructor and one for the event_instructor_status and one for another entity).   Interestingly enough, the event_instructor's event_instructor_status field is "null" but the internal _status is "T".

The event_instructor_status entity has "R".  So somehow the event_instructor.event_instructor_status is null.

On the server side, I'm doing (in the query)

IQueryable<event_instructor> insSet = this.Context.event_instructor.Include("event_offering").Include("event_instructor_status").Where((row) => row.EvtIns_Id == id);

I'm not quite yet sure why the client is losing it's connection between event_instructor and event_instructor_status.   If I have to tie them back together again on the client, I can *but* that will cause the entity framework to think that an "update" needs to be performed again when it does not  :-(

thanks.

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities