Note that there are some explanatory texts on larger screens.

plurals
  1. POEntityDataSource accessing a collection from another entity in GridView
    text
    copied!<p>I'm not sure if my title accurately describes what I'm trying to do.</p> <p>I have two tables in my Entity Framework, person and user. I am trying to display a grid of users, so I set up this EntityDatasource:</p> <pre><code>&lt;asp:EntityDataSource ID="peopleQuery" runat="server" ConnectionString="name=myEntities" DefaultContainerName="myEntities" EnableFlattening="False" EntitySetName="people" Include="location" Where="it.active = 1" OrderBy="it.lastname, it.firstname"&gt; &lt;/asp:EntityDataSource&gt; </code></pre> <p>Now in my GridView, I can bind to fields like lastname, firstname, emailaddress, and fields from the location table like address and city.</p> <p>Now, in my system, a user record can be attached to one or more person records. So it's a 1-to-many relationship. In the gridview, I would like to display the users associated with each person. I can do it with a RowDataBound event, but that requires an extra DB lookup for every row in the database.</p> <p>Is there some efficient way to navigate from the "many" end of a "1-to-many" foreign key relationship?</p> <p>Actually, it doesn't even have to be 1-to-many. It could be 1-to-1, but you're on the other end of the foreign key relationship. So, in this example, the EntityDataSource uses the "person" table, but in the user table, I have a personid field. So the foreign key is user.personid => person.personid. Since the GridView is driven from the user person table, how can I navigate to the user table to display user.username in my GridView?</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