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 643039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:14:23+00:00 2026-05-13T21:14:23+00:00

I have two SQL Server tables with Primary Keys (PK) and a Foreign Key

  • 0

I have two SQL Server tables with Primary Keys (PK) and a Foreign Key (FK) linking the two tables:

1) Table "Order"

OrderID, int, PK  
AddressID, int, FK
...

2) Table "Address"

AddressID, int, PK
City, nvarchar(50)
...

Then I’ve created an (ADO.NET) Entity Data Model out of those two tables.
Now on my (ASP.NET) webpage I put a GridView with an EntityDataSource. In my GridView I want to display two columns:

  • OrderID
  • City (belonging to that order and linked by the AddressID-key)

How can I do that? My problem is: When I configure the Entity Data Source I can select an “EntitySetName” which can be
either “Order” or “Address” but not both, nor can I select any kind of relationship. If I select “Order” as EntitySetName
then in the GridView I can add the columns

  • OrderID
  • Address
  • Address.AddressID

Adding the column “Address” displays empty cells. Adding “OrderID” and “Address.AddressID” displays the expected IDs. But how can I
add the “City” of the related address to my GridView?

Thank you for help in advance!

Edit: Clarification:

The Entity Framework has created a class “Order” and a class “Address” corresponding to the database tables. The class “Order” has a reference to an “Address” object as a navigation property, corresponding to the 1-n relationship between Address and Order table.

Basically I want to have a column in my GridView which displays Order.Address.City. I have tried to add a bound field with “Address.City” as data field to the GridView but it results in a runtime error (“no such property…”).

  • 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-13T21:14:23+00:00Added an answer on May 13, 2026 at 9:14 pm

    OK, much too many hours later I found the solution myself:

    Option 1:

    It is possible to use the select property in the EntityDataSource which allows to create arbitrary projections of data from several related entities/database tables (in my case: OrderID from Order entity and City from the
    Address entity)

    Drawback: Using select in the EntityDataSource makes using Insert, Update and Delete in the GridView impossible!

    Option 2:

    The EntityDataSource must have the include property to include the related address property along with the queried orders. The markup looks likes this:

    <asp:EntityDataSource ID="EntityDataSourceOrders" runat="server" 
        ConnectionString="name=MyEntitiesContext" 
        DefaultContainerName="MyEntitiesContext" 
        EntitySetName="Order" Include="Address"
        EnableDelete="True" EnableInsert="True" 
        EnableUpdate="True">
    </asp:EntityDataSource>
    

    Then the columns collection of the GridView can have a template field like this:

    <asp:TemplateField HeaderText="City" >
      <ItemTemplate>
        <asp:Label ID="LabelCity" runat="server" Text='<%# Eval("Address.City") %>'>
        </asp:Label>
      </ItemTemplate>
    </asp:TemplateField>
    

    Here Eval is important. Bind does not work. Also using a BoundField as a column…

    <asp:BoundField DataField="Address.City" HeaderText="City" />
    

    … is NOT possible. So it is not possible in the GridView to edit the City (which makes sense because its a related field belonging to another table and perhaps to many other orders). But it is possible to edit flat fields of the order entity and also the “AddressID” of the order to assign another address.

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

Sidebar

Related Questions

I have two tables: CREATE TABLE InmarsatZenith.dbo.ClientJob (JobRef int PRIMARY KEY NOT NULL, IntRef
In SQL Server 2008 I have two tables. One table for users: id_user -
we have two related tables(inventory and inventoryLocalization) on Sql Server 2005. the first table's
I have two tables like this. Table A A_ID ( Primary Key) A1 A2
i have a table with two foreign keys as composite key. ActivityTbl - (activityNbr(PK),
I have two tables in SQL Server, tbl_disputes and tbl_disputetypes . The tbl_disputes table
I have two identical SQL Server tables ( SOURCE and DESTINATION ) with lots
I have two tables in Sql Server, one containing IDs for files and the
We have two tables in a SQL Server 2005 database, A and B.There is
In SQL Server 2008: I have two tables, dtlScheme and dtlRenewal, with a one

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.