Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 947505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:05:33+00:00 2026-05-15T23:05:33+00:00

I have a very simple mockup I’m making for a client that uses the

  • 0

I have a very simple mockup I’m making for a client that uses the Northwind database. I have an EDMX file with three entities: Products, Categories, and Suppliers.

I’m trying to create a page that has a GridView that shows the products, including the category name and supplier name. With LINQ to SQL I can have the LinqDataSource control return the Products entity and then can have a TemplateField in the GridView like so:

<ItemTemplate>
    <%# Eval("Category.CategoryName") %>
</ItemTemplate>

However, it seems the EntityDataSource is not playing so nicely. It’s as if it won’t lazy load the category data. I have a very simple EDS:

<asp:EntityDataSource ID="dsProducts" runat="server" 
    ConnectionString="name=NorthwindEntities" 
    DefaultContainerName="NorthwindEntities" EnableFlattening="False" 
    EntitySetName="Products">
</asp:EntityDataSource>

But the GridView does not show the category name. If I create a RowDataBound event handler for the GridView and get the Product entity being bound to the row, I see that the product’s Category property returns Nothing. For example, if I do:

Protected Sub gvProducts_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvProducts.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim p As NorthwindModel.Product = e.Row.DataItem
        Dim catName = p.Category.CategoryName
    End If
End Sub

I get a NullReferenceException when trying to do p.Category.CategoryName.

However, I know lazy loading works for the EDMX b/c if I write code in the Page_Load event handler like:

    Dim context As New NorthwindModel.NorthwindEntities
    Dim p = context.Products.Take(1).Single()

I can get the Category name via p.Category.CategoryName without error.

Is there some voodoo I need to do to get the EntityDataSource to include support for retrieving related entities?

Thanks

SOLUTION:
I specified the Include property of the EntityDataSource, noting the entity objects to include. Specifically, I updated my EntityDataSource control’s declarative markup to:

<asp:EntityDataSource ID="dsProducts" runat="server" 
    ConnectionString="name=NorthwindEntities" 
    DefaultContainerName="NorthwindEntities" EnableFlattening="False" 
    EntitySetName="Products" Include="Category,Supplier">
</asp:EntityDataSource>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:05:33+00:00Added an answer on May 15, 2026 at 11:05 pm

    You need to use the Include property of the entity data source to get related entities. Then, change the markup to query into these entities.

    Take a look a a couple of pages from the book “Programming Entity Framework”: http://books.google.com/books?id=wp8V0vBebnoC&pg=PA284&lpg=PA284&dq=entitydatasource+include&source=bl&ots=cKtfB1J8vC&sig=C–WGKuU-9CNOQgDxdN0MpSMLt4&hl=en&ei=OidPTMnKB5P-ngeM1rinBw&sa=X&oi=book_result&ct=result&resnum=7&ved=0CDAQ6AEwBg#v=onepage&q=entitydatasource%20include&f=false

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple class that opens a file and creates a memory
i have very simple problem. I need to create model, that represent element of
I have a very simple bit of script that changes the status of an
I have a very simple Java RMI Server that looks like the following: import
I have a very simple ASP.Net page that acts as a front end for
I have very simple form along with two database tables. In this form is
I have a very simple .NET commandline application that I want to port to
I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have a very simple problem which requires a very quick and simple solution
I have a very simple WPF application in which I am using data binding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.