New Posts New Posts RSS Feed: Problem with Navigation Properties
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Problem with Navigation Properties

 Post Reply Post Reply
Author
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post Topic: Problem with Navigation Properties
    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
Back to Top
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
pk55 View Drop Down
Senior Member
Senior Member


Joined: 22-Jul-2009
Location: CA
Posts: 105
Post Options Post Options   Quote pk55 Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
pk55 View Drop Down
Senior Member
Senior Member


Joined: 22-Jul-2009
Location: CA
Posts: 105
Post Options Post Options   Quote pk55 Quote  Post ReplyReply Direct Link To This Post Posted: 12-Aug-2011 at 10:43am
Thanks for the update and yes we'd take a patch build with a fix.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 12-Aug-2011 at 10:58am
Sure thing.
I'll send you a message as soon as it's fixed.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down