Alex Rivera | Logout

How do you construct a LINQ to Entities query to load child objects directly, instead of calling a Reference property or Load()

Asked 2008-11-25T00:22:40.647
46

I'm new to using LINQ to Entities (or Entity Framework whatever they're calling it) and I'm writing a lot of code like this:

var item = (from InventoryItem item in db.Inventory
            where item.ID == id
            select item).First<InventoryItem>();

and then calling methods on that object like this:

var type = item.ItemTypeReference;

or

var orders = item.OrderLineItems.Load();

to retrieve child or related objects.

I haven't profiled the DB or dug too deeply but my guess is that when I call a .Load() or a *Reference property I'm actually making another call to the DB. If this is the case, is there any way to get those objects in my initial LINQ expression?

Edit
Report

1 Answer

0

AFAIK, For silverlight(domain services) adding [Include] attribute to right place(over navigation property in metadata) is enough https://stackoverflow.com/a/5332188/413032

answered 2013-03-23T14:24:01.860

Your Answer