Linq to Entities and Entity Framework Include() a few of tables, or

entity-framework include linq-to-entities

Question

I keep all the values I need to explain certain attributes of the database table rows in a table in my database called PropertyValues.

Table Products, for instance, would look something like this:

ID
OrderID //Products table is related with Order table
ProductName
ProductType_ID // ID of PropertyValues table which describes product type (food, parfume, chemicals)
ProductCountry_ID // ID of PropertyValues table which links to country where product came from ProductStatusID //also ID of PropertyValues table which contains product status(availible, not availible)

With this database schema, I'll have to create something along these lines to obtain the order and all of its goods, along with their kind, nation, and status:

var orders = from o in dbEntities.Order.Include("Products.ProductType")
                                       .Include("Products.ProductCountry")
                                       .Include("Products.ProductStatus")
            select o;

and hence the query is:
Does it work automatically? ( so all related entities will be included )
maybe there is a better course of action?

Thanks a lot!

1
2
5/27/2009 2:13:23 PM

Accepted Answer

I think what you are looking for is either "Lazy Loading" or "Eager Loading" as Alex James pointed out.

According to this blog post, Entity Framework version 4.0 will have "Lazy Loading."

http://blogs.msdn.com/adonet/archive/2009/05/12/sneak-preview-deferred-loading-in-entity-framework-4-0.aspx

You may set it up automatically by searching for "Entity Framework Lazy Loading" online.

2
6/1/2009 5:09:23 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow