I'm not sure if my title accurately describes what I'm trying to do.
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:
<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">
</asp:EntityDataSource>
Now in my GridView, I can bind to fields like lastname, firstname, emailaddress, and fields from the location table like address and city.
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.
Is there some efficient way to navigate from the "many" end of a "1-to-many" foreign key relationship?
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?