Entity Framework include style join


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //gets product and joins to ProductType to get associated type, then from there to product category to get the category associated with the type.
  2. Entities db = new Entities();
  3. rptProducts.DataSource = db.Products.Include("ProductType.ProductCategory");
  4. rptProducts.DataBind();
  5.  
  6. //The webform:
  7. //Note the use of .eval instead of GetPropertyValue when calling properties that contain nested objects.
  8. <tr class="product_row" rel="<%#DataBinder.GetPropertyValue(Container.DataItem, "ProductID") %>">
  9. <td><asp:CheckBox runat="server" ID="chkProduct" /></td>
  10. <td><%# DataBinder.Eval(Container.DataItem, "ProductType.ProductCategory.Name") %></td>
  11. <td><a href="Edit?id=<%# DataBinder.GetPropertyValue(Container.DataItem, "ProductID") %>"><%# DataBinder.Eval(Container.DataItem, "ProductType.Name") %></a></td>
  12. <td><%# DataBinder.GetPropertyValue(Container.DataItem, "DateCreated") %></td>
  13. </tr>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.