Print Page | Close Window

Problem with Navigation Properties

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2885
Printed Date: 25-May-2025 at 4:55pm


Topic: Problem with Navigation Properties
Posted By: stephenmcd1
Subject: Problem with Navigation Properties
Date Posted: 10-Aug-2011 at 2:22pm
After upgrading to 6.1.2.0, we've started experiencing some odd behavior with Navigation Properties.  I've been trying to isolate the code that is causing problems or reproduce the bad behavior in a NorthwindDb, but I haven't had much luck.

As I said, I haven't had much problems narrowing it down, but sometimes Navigation Properties will have the Null Entity in them, even though the referenced entity is in the cache.  Also, we have all our Navigation Properties set to ReferenceStrategy.NoLoad.  So code like this works fine:

const int orderId = 10248;

//I can get the order details out of the EM like this - so I know they are in the cache
var details1 = em.OrderDetails.With(QueryStrategy.CacheOnly).Where(od => od.OrderID == orderId).ToList();

//details1 will now have 3 items in it

//Grab the order and then try to get it's details with the navigation property...
var order = em.Orders.With(QueryStrategy.CacheOnly).Single(o => o.OrderID == orderId);
//order is the correct entity

var details2 = order.OrderDetails.ToList();
//details2 is just an empty list!

This all worked fine before we upgraded to 6.1.2.0 - in fact, it even worked in an early 6.1.2 build that you gave us (I believe it was 6.1.2.0e.

The way we load data into our entity manager could be part of the problem.  We bulk load data through multiple InvokeServerMethodAsync calls that return EntityCacheStates.  The problem only seems to happen when the two entities involved (in the case above, that would be Order and OrderDetails) are loaded in two different batches.  I'm thinking maybe there is a problem with how the navigation properties get 'fixed up' when RestoreCacheState is called.

I'm still trying to see if I can narrow down the problem further but I wanted to post here in case there is anything that might jump out....or something that maybe I should check.

Thanks,
-Stephen



Replies:
Posted By: stephenmcd1
Date Posted: 10-Aug-2011 at 5:16pm
After further investigation, I have more information.  I don't know if the following is related to my original issue but it seems like it might be.

It seems that EntityReferenceStrategy.NoLoad causes Includes to be broken - and I was able to reproduce this in a Northwind database pretty easily.  For example, this code works with no problems:

var em = new NorthwindIBEntities();
        
//Grab a particular employee and his/her orders (testing on the server so we can do it synchronously)
var employeeAndOrders = em.Employees.Include(e => e.Orders).Single(e => e.EmployeeID == 5);
        
//See what Orders are in the cache
var orders1 = em.FindEntities<Order>(EntityState.AllButDetached).ToList();
        
//See what Orders are in the Navigation Property
var orders2 = employeeAndOrders.Orders.ToList();

//There should be 42 in both
Assert.AreEqual(42, orders1.Count);
Assert.AreEqual(42, orders2.Count);

But just by adding:

Employee.PropertyMetadata.Orders.ReferenceStrategy = EntityReferenceStrategy.NoLoad;

the test will fail and both lists will be empty.  Previously, the Reference Strategy didn't affect includes.  Did something change with this?  I'm guessing this issue is related to the one I'm having above where the Navigation Properties aren't getting populated.


Posted By: sbelini
Date Posted: 10-Aug-2011 at 6:52pm

Thanks for the update Stephen,

 
I am in the process of reproducing the issue here and will file a bug.
 
Silvio.


Posted By: pk55
Date Posted: 12-Aug-2011 at 10:32am
Any update on this?  We have to decide if we're going to back off of the official 6.1.2 release and go back to the 6.1.2."e" patch build (we need the stored procedure fixes but don't care about code first). And we have to decide that by Monday.


Posted By: sbelini
Date Posted: 12-Aug-2011 at 10:42am
Hi Stephen,
 
I submitted the bug yesterday. (08/11/11)
While we still don't have a fix, we are working on it and I will let you know as soon as it's done as well as provide you with a patch (if you wish so).
 
Kind regards,
   Silvio.


Posted By: pk55
Date Posted: 12-Aug-2011 at 10:43am
Thanks for the update and yes we'd take a patch build with a fix.


Posted By: sbelini
Date Posted: 12-Aug-2011 at 10:58am
Sure thing.
I'll send you a message as soon as it's fixed.



Print Page | Close Window