views:

720

answers:

1

Hi.

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 !

+2  A: 

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.

MPiccinato
Just to be clear 'Lazy' or Deferred loading, is not the same as eager loading. Which is strictly speaking what is being asked for, however I think you were right to highlight lazy-loading because it is probably what is really needed. Eager loading does just one query. Where as lazy-loading provides the illusion that the related objects are loaded in one query, when in fact they are not. As related objects are accessed the EF silently issues additional queries.
Alex James