Title: EF4 STE include-path....exclude-path?
Tags: entity-framework;entity-framework-4;domain-driven-design;repository-pattern;self-tracking-entities
Question: Context: Repository-pattern, WCF, WPF/SL
In my Repository of self-tracking Entities i need to explicitly load some related properties in order to correctly process the query. Those are not the includes requested by the client and i would like to get rid of them in order to keep network traffic resonable. My solution so far is this:
Receive Query
Load includes necessary to answer request
Execute Query
Create temporary IEnumerable
Iterate 4) and load all items again, this time with the include-path requested from the client-app only
return entities via WCF
I would like to do this:
Receive Query
Load all includes (infrastructure plus client-requested)
Execute Query
Unload &quot;Infrastructure&quot; includes
return entities via WCF
What is the proper way to do this?
Thanks,
Comment: Maybe you can load just required graph of objects and then get additinal Entities/Collections. One more solutions is just to use select extension to cut includes in object graph.


Here is another answer: How about lazy loading and proper DTO response objects ?
WCF returns custom Order or GetOrderResponse (Contracts.Order)
Load Order from EntityModel through repository (just the order)
Use automapper for mapping EntityModel.Order => Contracts.Order
Result : only the corresponding properties inside Contracts.Order are loaded:
Ex. Contracts.Order
Number
OrderDetails (=> Only this property is loaded through lazy loading because it is mapped)
If you are building a SOA or webservice, don't let the client specify load graphs. If it's necessary for the client to specify load graphs consider deploying the Model using WCF Data Services, works great.
Perhaps you could build two systems .. one SOA and one (readonly) Data Service.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 2.5', 'CreationDate': '2011:00:02/21/11', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<entity-framework><entity-framework-4><domain-driven-design><repository-pattern><self-tracking-entities>', 'Title': 'EF4 STE include-path....exclude-path?', 'ViewCount': 403, 'id': 5068314, 'user_AboutMe': '', 'user_AccountId': 294615.0, 'user_DisplayName': 'armin o', 'user_Reputation': 135.0, 'user_Views': 8.0, 'user_id': 598609.0}}