Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC with nested actions, WCF Data Service with EF5, and DataServiceQuery<>.Expand()
    text
    copied!<p>Consider this code:</p> <pre><code>var svc = new ProductDesignerEntities(AppSettings.ProductDesignerServiceLocation); var scenariox = svc.Scenarios .Where(o =&gt; o.ID == id) .FirstOrDefault(); var scenario = svc.Scenarios .Expand(o =&gt; o.SomeNavigationProperty) .Where(o =&gt; o.ID == id) .FirstOrDefault(); </code></pre> <p>When this code runs, <code>scenario.SomeNavigationProperty</code> will be unpopulated. Commenting out the code which populates <code>scenariox</code> fixes it. Why is this? Is it possible to fix this through configuration of the service context or the data service, or will I have to change the design of my code in some fashion?</p> <p>The alternatives that I can think of are all inferior in some capacity:</p> <ul> <li>Create a <code>ProductDesignerEntities</code> instance per action. This kills within-request caching almost entirely.</li> <li>Create a <code>ProductDesignerEntities</code> instance per controller. Less annoying with a base controller class, but this kills caching between controllers, and wouldn't fix the issue if different actions in the same controller needed different sets of navigation properties from the same table.</li> <li>Manually populate the property if it is empty. Difficult to consistently implement a manual solution like this; bound to be a source of bugs.</li> <li>Always manually populate the property. Kind of defeats the purpose of navigation properties.</li> <li>Ensure that all uses of the table within a request have the same .Expand() list. Extremely annoying and begging for hard-to-fix bugs.</li> </ul> <p>I'm starting to lean toward the first alternative. It seems to have the least issues, despite the additional overhead of a new connection for each instance :/</p> <p><strong>EDIT:</strong> I managed to get the service queries to run through Fiddler, and they look correct. But the navigation property on <code>scenario</code> still winds up empty unless I comment out the <code>scenariox</code> code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload