Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF RIA EntityQuery returns null for Foreign Keys
    text
    copied!<p>I'm following a <a href="http://www.silverlightshow.net/items/Working-with-Prism-4-Part-3-Composite-Command-and-Pub-Sub-Events.aspx" rel="nofollow noreferrer">tutorial</a> on Silverlight and Prism, where <strong>WCF RIA Services</strong> are uses to access the <strong>Northwind database</strong> through an <strong>ADO.NET Entity Data Model</strong>.</p> <p>In the Northwind database, there is a table Order_Details which is connected to two other tables (Orders and Products) via foreign keys:</p> <p><img src="https://i.stack.imgur.com/iTm74.png" alt="Picture of Data Model"></p> <p>The code to query the database looks like this:</p> <pre><code>EntityQuery&lt;Order_Detail&gt; detailQuery = _MyDomainContext.GetOrder_DetailsQuery(); _MyDomainContext.Load(detailQuery.Where( det =&gt; det.Order.Customer.CustomerID == cust.CustomerID).OrderByDescending( det =&gt; det.Order.OrderDate).Take(10), OnDetailsLoaded, null); </code></pre> <p>and then in OnDetailsLoaded:</p> <pre><code>var details = loadOp.Entities; if (details != null) { var detailsList = details.ToList(); detailsList.ForEach(det =&gt; Orders.Add( new OrderItem { ProductName = det.Product.ProductName, Quantity = det.Quantity, OrderDate = det.Order.OrderDate.Value })); </code></pre> <p>This gives me a Null Exception at <code>new OrderItem</code>, because both Product and Order are null. I have set my EntityDataModel to "Include Foreign Key Columns in the Model". The code is exactly as in the tutorial, I only had to recreate the ADO.Net EntityDataModel and the DomainService to work with my local database, so the error is probably somewhere there.</p> <p>How would I debug this error? I have no previous experience with databases. I'm using SQL Server 2012 with a Northwind database adapted for 2012, while the tutorial was written with SQL Server 2008 RC.</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