Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display with Entity Framework value of a foreign key

I'm working on a grid where I want show not the value of the connected foreign key but it should not look like (1,2,3,57 etc) that is already working ... I want to show really the value behind the numbers like (test,lead,foo,bar etc..) I think that should be possible

I'm using Entity Framework 5.0 with asp.net 4.5

My EntityDataSource:

<asp:EntityDataSource ID="EntityDataSource1" runat="server" 
     ConnectionString="name=zevtestEntities" DefaultContainerName="zevtestEntities" 
     EnableFlattening="False" EntitySetName="BU"></asp:EntityDataSource>

I have already tried:

<telerik:GridBoundColumn
    DataField="ZevUser.FirstName" FilterControlAltText="Filter Creator column"
    HeaderText="Creator" ItemStyle-Width="60px" SortExpression="Creator" UniqueName="Creator">
    <ItemStyle Width="60px" />
</telerik:GridBoundColumn>

And ZevUser is the source table where the values are stored as text, is there another way to do it?

like image 506
laserbear Avatar asked Oct 05 '22 09:10

laserbear


1 Answers

You almost have it. You can reference the related entity in EF using the include property in your EntityDataSource. Try Include="ZevUser" after your EntitySetName. See the below link for more information.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.entitydatasource.include.aspx

like image 113
Juan Avatar answered Oct 13 '22 10:10

Juan