views:

41

answers:

1

Having created a standard Silverlight Business Application in VS2010 and set up a model from a SQL Server database, I have various entities and associations, among which AssetGroup and Asset are in a 1:m relationship.

Allegedly I can use dot notation to get the associated AssetGroup out of an asset instance. Through the modern miracles of deferred execution and lazy loading, I am assured, my data will be delivered the very moment that I need it.

But it doesn't work.

What are the required incantations, and do I have to slay a chicken or a goat?

This looks promising. As soon as I've tried it out I'll update.

A: 

In the question I mention a blog post containing a possible solution. That solution works, but entails changes to generated code, which is obviously as fragile as a solution gets.

Here's a robust way to apply the solution: change the code generator.

  1. On the EDMX designer surface right-click for the context menu and choose Add Code Generation Items...
  2. Try to improve on "Model1.tt" as a name and save the TT file.
  3. Open the TT file.
  4. Search for "return (" to directly find the method template you need to change.
  5. Edit as shown.
  6. Rebuild the solution.

Change this

return /* big hairy expression */;

to this

var entity = /* big hairy expression */;
if (!entity.IsLoaded) entity.Load();
return entity;
Peter Wone