Hello,
In Microsoft EF, we were able to do something like the following:
// In Microsoft EF, c.Orders.Count == 7
Customer c = em.Customer.Where(i => i.Name.BeginsWith("R")).Include("Orders").FirstOrDefault();
if (c != null)
Console.WriteLine(c.Orders.Count);
And as expected, the first Customer or null would be returned, and if not null the print out of the number of orders would be accurate. When we try the same in DevForce EF it doesn't appear to work the same. (I need to note that we're talking straight DevForce EF here, not SL). The Customer will come back, but the number of orders is always 0, as if the Include() is not being used.
// In DevForceEF, c.Orders.Count == 0
Customer c = em.Customer.Where(i => i.Name.BeginsWith("R")).Include("Orders").FirstOrDefault();
if (c != null)
Console.WriteLine(c.Orders.Count);
What does seem to work is either of the following:
Customer c = null;
foreach (var item in em.Customer.Where(i => i.Name.BeginsWith("R")).Include("Orders"))
{
c = item;
break;
}
if (c != null)
Console.WriteLine(c.Orders.Count);
Or:
Customer c = em.Customer.Where(i => i.Name.BeginsWith("R")).Include("Orders").Execute().FirstOrDefault();
if (c != null)
Console.WriteLine(c.Orders.Count);
However, if we change the FirstOrDefault() to FirstOrNullEntity(), the "Execute()" solution will fail to compile.
Is this working as expected or are we doing something wrong?
Thanks,
Ken
Edited by ken.nelson - 13-Mar-2009 at 11:15am