Problem REloading entity that has been changed on the server side RRS feed

  • Question

  • Hi SL team,

    I am having a problem with reloading an entity from the server side.
    - SL 4.0 client invokes SL RIA service1 and received 100 order with complex graph
    - Reloading one entity that has been changed on the server side fails, complex graph is not reloaded

    0. My object Order has 1:M relationship to Car. Order has the Cars property

    public class Order

    [Association("OrderCars", "Id", "ParentId")]
    public List<Car> Cars {..}


    1. I load 100 objects of type Order into SL client. The ctx.Orders has all the 100 orders
    AND all the cars are materialized and loaded too. Everything works nicely

    ctx.Load(result,LoadBehavior.MergeIntoCurrent,true).Completed += (s, e) =>
    this.items.Source = (s as LoadOperation<Order>).Entities;

    2. When I try to reload a specifc entity that has been modified on the server side, the load fails
    in as such that the Order instance is loaded correctly, but the Cars property is empty/contains no cars.

    var result = ctx.GetOrderByOrderId2Query(orderId);
    ctx.Load(result,LoadBehavior.RefreshCurrent,true).Completed += (s, e) =>
    var ol = (s as LoadOperation<Order>).Entities.ToList();
    // ol.First() contains my correct Order object
    // ol.First().Cars.Count() == 0. No legs loaded ?
    // CARS list is empty !!! why ???

    3. the server side GetOrderByOrderId2Query works nicely and returns the correct data

    Your advise is much appreciated

    Wednesday, March 28, 2012 4:18 PM


  • Just a big thank you to Colin for his feedback. I solved the problem : the issue was that some other code changed/corrupted the Ctx.Orders in the background, causing the reload to fail.



    Friday, March 30, 2012 12:32 PM

All replies

  • Check the differences between the two server side query methods. Do they have the same includes? Have you used Fiddler to see if the reload has the Cars in the communication? That will help you track down if the problem is server side or client side.

    Thursday, March 29, 2012 10:23 AM
  • Hi Colin,

    thanks for your feedback.

    1. I used Fiddler, and the CARS dependant object is returned

    2. I am not sure about what you mean by "Includes". Here are the queries

    a) Query that returns the 100+ Orders incl. the entire graph

      // Get the order based on storageId
    public IEnumerable<Order> GetOrdersLiveAndDate(DateTime allOfDate)
    var to = DateTime.Now;

    var results = GetDB().RetrieveAll<Order>();
    var results2 = results.Where(o => ( o.BOModified.Date == allOfDate.Date || o.BOCreated.Date == allOfDate.Date) || o.OrderStatus == OrderStatuses.OPEN).Select(l => l).ToList();
    Logger.InfoFormat("GetOrdersLiveAndDate took {0}ms", (DateTime.Now - to).TotalMilliseconds);

    return results2;
    catch (Exception ex)
    Logger.ErrorFormat("GetOrdersLiveAndDate. Exception {0}", ex);

    return new List<Order>();
    b) The query that returns the entire order, incl. chidlren
    public IEnumerable<Order> GetOrderByOrderId2(string orderId)
    // Timing
    DateTime dt1 = DateTime.Now;

    // Get results
    var results = GetDB().RetrieveByKey<RevCapOrder.Server.Model.Order>("id",orderId);

    // Return time
    Logger.InfoFormat("Loading order by orderId {1} took {0} milliseconds. Success ={2}", (DateTime.Now - dt1).TotalMilliseconds, orderId, results!=null);

    // Create list of results
    var ret = results == null ? new List<Order>() { } : new List<Order>() { results };
    return ret;
       I set breakpoints at the end of both queries, and they both return the CARS.
       Thanks a lot in advance 
    Thursday, March 29, 2012 11:11 AM
  • If Fiddler shows the cards then we can get past the server side and figure out why the client side isn't getting its cars. There are two things I can think of

    1. Are the foreign keys in Fiddler correct? Meaning, does the ParentId in the cars match the Id of the Order?
    2. I recently had someone having trouble doing a reload because an MVVM framework they were using marked every entity as being edited thorugh the IEditableObject interface. In your breakpoint where cars is not loaded, check the value of IsEditing. It is an internal value so you can only access it through the debugger. If it is true, then track down what is calling BeginEdit on the entity without ending the editing session.

    If neither of those work, then I would suggest detaching the entity from the DomainContext before reloading and see what happens then. If the "reload" results in a complete object that will give us additional information.

    Thursday, March 29, 2012 11:35 AM
  • 1. Yes, I checked ParentId <--> Order.Id. They match in fiddler

    2. I looked into ctx.Order where ctx is my Domain Context

    a) ctx.HasChanges = true

    b) ctx.Order._interestingEntities.Count() ==1 ==> Order in question

    c) ctx.Order._interestingEntities[0].Modified = true

    d) ctx.Order._interestingEntities[0]._hasChildChanges = true

    IsEditing == false 

    3. I detached the object to no avail.

    4. I deleted the object to no avail.

    It works if the reload is an entire new Order that cannot be found in the entityCollection.

    Any ideas would be very appreciated.

    Thanks in advance


    Thursday, March 29, 2012 12:32 PM
  • Just a big thank you to Colin for his feedback. I solved the problem : the issue was that some other code changed/corrupted the Ctx.Orders in the background, causing the reload to fail.



    Friday, March 30, 2012 12:32 PM