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

entity-framework include linq-to-entities

Question

i've got a database with a table named PropertyValues where i store every value i need to describe some properties of my database table rows.

For example, table Products which looks 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 such database model, to get order and all it's products with their type, country and status i'll have to write something like this :

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

and the question is :)
can it be done automatically ( so all related entities will be included )
or maybe there is better approach ?

Thank You !

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.

This blog post explains that "Lazy Loading" is to be implemented in version 4.0 of the Entity Framework.

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

It can be done automatically, Google "Entity Framework lazy loading" to go about setting it up.

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