New Posts New Posts RSS Feed: Include() and FirstOrNullEntity()
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Include() and FirstOrNullEntity()

 Post Reply Post Reply
Author
JulianBenjamin View Drop Down
Newbie
Newbie
Avatar

Joined: 03-Aug-2007
Location: United States
Posts: 10
Post Options Post Options   Quote JulianBenjamin Quote  Post ReplyReply Direct Link To This Post Topic: Include() and FirstOrNullEntity()
    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) and it's still not returning items.
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: 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.
Back to Top
JulianBenjamin View Drop Down
Newbie
Newbie
Avatar

Joined: 03-Aug-2007
Location: United States
Posts: 10
Post Options Post Options   Quote JulianBenjamin Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
JulianBenjamin View Drop Down
Newbie
Newbie
Avatar

Joined: 03-Aug-2007
Location: United States
Posts: 10
Post Options Post Options   Quote JulianBenjamin Quote  Post ReplyReply Direct Link To This Post 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.
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: 31-Jan-2011 at 5:08pm

Glad you found the issue.

Thanks for the update.
 
Silvio.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down