Print Page | Close Window

Navigation property trouble

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2711
Printed Date: 20-Apr-2024 at 1:31pm


Topic: Navigation property trouble
Posted By: tjuncewicz
Subject: Navigation property trouble
Date Posted: 24-May-2011 at 1:02pm
Does anyone know of an issue of using the EntityCacheState returned from an InvokeServerMethodAsync call when it comes to navigation properties?  We retrieve a master object in the RPC, using an Include() to make sure the details are also returned, then return the entire ECS.  We merge the ECS back into our main EM in our callback function, but whenever we access the master object's navigation property it still goes back to the server to get the details, even through the details were returned as part of the ECS.  Is the serialization/deserialization process "losing" the navigation property "linkage"?
 
Thanks.



Replies:
Posted By: DenisK
Date Posted: 24-May-2011 at 6:08pm
Hi tjuncewicz;

I was not able to repro this. This might be an old bug that has been fixed in the latest 6.1.0 version.  What DevForce version are you using?

I've included my test below.

RPC Method

    [AllowRpc]
    public static EntityCacheState GetCustomerWithOrders(IPrincipal principal, EntityManager em, params Object[] args) {
      var baseQuery = em.GetQuery<Customer>()
        .Where(c => c.Id == 1);
      baseQuery.Include(c => c.OrderSummaries);

      var customerResults = baseQuery.ToList();
      var includedOrders = customerResults.First().OrderSummaries.ToList();

      var customerInCache = em.FindEntities<Customer>(EntityState.AllButDetached).ToList();
      var includedOrdersInCache = em.FindEntities<OrderSummary>(EntityState.AllButDetached).ToList();
      var allEntitiesInCache = em.FindEntities(EntityState.AllButDetached).OfType<Entity>().ToList();

      if (customerResults.Count != customerInCache.Count ||
        includedOrders.Count != includedOrdersInCache.Count ||
        allEntitiesInCache.Count != (customerResults.Count + includedOrders.Count)) {

        throw new IdeaBladeException("Cache does not have the same count");

      }
      var entityCacheState = em.CacheStateManager.GetCacheState();

      return entityCacheState;
    }

Main Method

    var op = mgr.InvokeServerMethodAsync(typeName, methodName, null, null, null);
      op.Completed += (o, args) => {
        Assert.IsFalse(args.HasError, "Should not have errors");
        Assert.IsTrue(args.Result is EntityCacheState, "ECS should be returned");
        var ecs = args.Result as EntityCacheState;
        mgr.CacheStateManager.RestoreCacheState(ecs);
        mgr.Customers
          .Where(c => c.Id == 1)
          .ExecuteAsync(queryOp => {
            var anotherCust = queryOp.Results.Cast<Customer>().First();
            Assert.IsFalse(anotherCust.OrderSummaries.IsPendingEntityList, "OrderSummaries should not be pending");
            var orders = anotherCust.OrderSummaries.ToList();
          });
      };



Posted By: tjuncewicz
Date Posted: 26-May-2011 at 8:20am
Thanks for the response.  We are using 5.2.7.


Posted By: DenisK
Date Posted: 26-May-2011 at 11:28am
I see. Is there any specific reason that's preventing you from upgrading to DevForce 2010?


Posted By: tjuncewicz
Date Posted: 03-Jun-2011 at 8:18am
Sorry for the delayed response.  Yes, there are a few reasons we haven't upgraded.  DF 2010 requires .Net 4, which requires purchase of VS2010 for all of my devs, plus a new set of licenses for our source control (which doesn't work with VS2010), plus new expression blend (we are using WPF) plus the T4 generator changed the naming for all of our navigation "ID" properties from "something_FK_something_ID" to just "somethingID" which would require overhauling a TON of XAML (we have 400+ entities and scores of screens).
 
Maybe I am mistaken in the requirements above?  We DO eventually plan on upgrading but we are already late on a project and fear this would cause even more havoc/delays..


Posted By: DenisK
Date Posted: 03-Jun-2011 at 5:00pm
I see. Unfortunately, it sounds like you're correct on the requirements.



Print Page | Close Window