Print Page | Close Window

Include() and FirstOrNullEntity()

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=2475
Printed Date: 08-Jun-2025 at 7:47am


Topic: Include() and FirstOrNullEntity()
Posted By: JulianBenjamin
Subject: Include() and FirstOrNullEntity()
Date Posted: 30-Jan-2011 at 12:25pm
When using the Include function, the FirstOrNullEntity doesn't fetch the included items; additionally, it seems it thinks it has queried for the related items, and so returns a nullentity for related entities even though removing the Include and then navigating the references triggers a query and returns the correct data.
 
Is this a bug?  my code is as follows:
 
EntityQuery<b2b_product> query =
(EntityQuery<b2b_product>)
BusinessGlobals.b2bEntityManager.b2b_product.Where(p => p.item_number == ItemNumber).Include("as400_itemex01");
return query.FirstOrNullEntity();
 
I've also tried the suggestion from this thread ( http://www.ideablade.com/forum/forum_posts.asp?TID=2430 - http://www.ideablade.com/forum/forum_posts.asp?TID=2430 ) and it's still not returning items.



Replies:
Posted By: sbelini
Date Posted: 31-Jan-2011 at 12:42pm
Hi JulianBenjamin,
 
I was not able to reproduce your issue.
Here's a simple test I ran against NorthwindIB:
 
public void TestInclude() {
var mgr = new IdeaBladeTest1Entities();
var query = mgr.Employees.Where(e => e.EmployeeID == 1).Include("Orders");
var employee = query.FirstOrNullEntity();
 
// all orders belonging to employee are loaded into cache
var orders = mgr.Orders.With(QueryStrategy.CacheOnly).Where(e => e.EmployeeID == 1).ToList();
}
 
Can you provide a simple solution (against NorthwindIB) reproducing your issue?
 
Regards,
Silvio.


Posted By: JulianBenjamin
Date Posted: 31-Jan-2011 at 1:37pm
I'm unable to reproduce with the NorthwindIB database.  I selected an InternationalOrder with an Include("Order") and got the first entity and pulling the Order record was fine.  My model had a similar association key (as400_itemex01 always has a record, but there may not be a b2b_product record for it).
 
I'm going to check more and try to narrow it down.


Posted By: JulianBenjamin
Date Posted: 31-Jan-2011 at 4:53pm
Figured it out; types were not the same (char15 vs varchar15); after setting the types to be the same, it worked correctly.


Posted By: sbelini
Date Posted: 31-Jan-2011 at 5:08pm

Glad you found the issue.

Thanks for the update.
 
Silvio.



Print Page | Close Window