简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM