5

I have problem to call WCF RIA service again to refresh data at client side. Here is my case:

At server side, a domain service is something like:

public IQueryable<Person> GetPersonByID(int id)
       {
           var result = this.ObjectContext.Persons.
               Where(e => e.PersonID == id);
           return result; // check point 1
       }

At client side, I make a call in the following way (this is call by a button I called "refresh" button):

this._amsService.Context.Load<Person>(
    this._amsService.Context.GetPersonByIDQuery(this.Person.ID),
    LoadBehavior.RefreshCurrent,
    result =>
    {
        this.Person = result.Entities.FirstOrDefault(); //check point 2
        this.RaisePropertyChanged("Person");     

    }, null);

Here is what I'm trying:

Suppose I have a person in DB with data say personID=1, Age = 16.

  1. Then run the app, I get the data in the right way.

  2. then go to database, update data with SQL to change Age = 20.

  3. Then back to app and click the "refresh" button to make a new call, but the age is not updated to 20, it is still 16.

I run the app in debug mode, and check the data:

At check point 1, I check data in result, it is fine, Age = 20.

At check point 2, I check data in result.Entities, the data has not been refreshed, it's still Age = 16.

I have tried LoadBehavior.MergeIntoCurrent,LoadBehavior.RefreshCurrent, but no success.

So I need to refresh the SL app host page to reload the whole SL app, then I can see the new data. This is not acceptable to end users.

I don't understand why. I also try to use fiddler to catch the data when click on refresh button, the data did get the latest Age = 20.

How to resolve this problem?

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
KentZhou
  • 24,805
  • 41
  • 134
  • 200
  • To be clear, what do you see when you set the breakpoint at "this.RaisePropertyChanged("Person");"? – Ed Chapel Dec 08 '11 at 17:44
  • Can you debug your server-side code, and see what that is returning? If the entity is cached in a session on the server side, this could be the reason the data isn't updating. Also, you don't need to re-set your person property on the client side, just run the query, and RIA services will raise the age property changed event on the current person. – Tevin Apr 22 '12 at 14:07
  • I think you should add submitchanges() in server side – Jignesh.Raj Apr 27 '13 at 05:21

1 Answers1

0

First of all, is you entity in edit mode? if you entity is in Edit mode, RIA will keep your changes , and only update the original values when you load the entity again.

You can check IsEditing property of your Person entity to find out. and try to check the OriginalValue of your entity. var original = Person.GetOriginal()

Johnny
  • 363
  • 1
  • 8