This is a migrated thread and some comments may be shown as answers.

Grid Column EntityFramework with related tables

1 Answer 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex Jimenez
Top achievements
Rank 1
Alex Jimenez asked on 20 Oct 2014, 12:40 PM
Hi, 

I have a telerik project with Entity Framework.

I want to show de value of the related tables in a GridBoundColumn, but ever come empty.

I Attach a picture showing the related tables, and the code in the aspx.

Please , someone can help me? Thanks

Code in ASPX

 

        <telerik:RadGrid ID="RadGrid1" runat="server" CssClass="RadGrid" GridLines="None"

        AllowPaging="True" PageSize="50" AllowSorting="True" AutoGenerateColumns="False"

        ShowStatusBar="true" AllowFilteringByColumn="True"

        DataSourceID="EntityDataSourceUsuarios" OnDeleteCommand="RadGrid1_RowDeleting" OnItemDeleted="RadGrid1_ItemDeleted"

        OnUpdateCommand="RadGrid1_UpdateCommand"  OnItemCommand="RadGrid1_ItemCommand" OnPreRender="RadGrid1_PreRender" AllowAutomaticUpdates="true"  >

       

        <MasterTableView DataSourceID="EntityDataSourceUsuarios" AutoGenerateColumns="False"

            DataKeyNames="ID" CommandItemDisplay="Top" PageSize="50">

 

Columns…..

<telerik:GridBoundColumn DataField="M_EMPRESAS.Descripcion" HeaderText="Empresa" SortExpression="M_EMPRESAS.Descripcion" UniqueName="M_EMPRESAS.Descripcion" >

                </telerik:GridBoundColumn>

                <telerik:GridBoundColumn DataField="M_TARIFAS.ID" HeaderText="Tarifa" SortExpression="M_TARIFAS.ID" UniqueName="M_TARIFAS.ID">

                </telerik:GridBoundColumn>

                <telerik:GridBoundColumn DataField="M_TIPO_ACCESO_TARJETA.ID" DataType="System.Int32" HeaderText="Acceso" SortExpression="M_TIPO_ACCESO_TARJETA.ID" UniqueName="M_TIPO_ACCESO_TARJETA.ID" >

                </telerik:GridBoundColumn>

Entitys…..

 

 
<asp:EntityDataSource ID="EntityDataSourceUsuarios" runat="server"

            DefaultContainerName="HARVESTEntities" EntitySetName="M_USUARIO" OrderBy="it.[CodEmpleado]"

            EntityTypeFilter="M_USUARIO" EnableUpdate="True" EnableDelete="True" EnableInsert="True" ConnectionString="name=HARVESTEntities">

        </asp:EntityDataSource>

        <asp:EntityDataSource ID="EntityDataSourceAccesoTarjeta" runat="server"

            DefaultContainerName="HARVESTEntities" EntitySetName="M_TIPO_ACCESO_TARJETA" OrderBy="it.[ID]"

            ConnectionString="name=HARVESTEntities">

        </asp:EntityDataSource>

        <asp:EntityDataSource ID="EntityDataSourceEmpresa" runat="server"

            DefaultContainerName="HARVESTEntities" EntitySetName="M_EMPRESAS" OrderBy="it.[ID]"

            ConnectionString="name=HARVESTEntities">

        </asp:EntityDataSource>

        <asp:EntityDataSource ID="EntityDataSourceTarifa" runat="server"

            DefaultContainerName="HARVESTEntities" EntitySetName="M_TARIFAS" OrderBy="it.[ID]"

            ConnectionString="name=HARVESTEntities">

        </asp:EntityDataSource>

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 23 Oct 2014, 10:54 AM
Hi,

To achieve the desired functionality you need to set the M_EMPRESAS, M_TARIFAS  and M_TIPO_ACCESO_TARJETA tables into the Include property of the EntityDataSource:
<asp:EntityDataSource ID="EntityDataSourceUsuarios" runat="server"
        DefaultContainerName="HARVESTEntities" EntitySetName="M_USUARIO" OrderBy="it.[CodEmpleado]"
        EntityTypeFilter="M_USUARIO" EnableUpdate="True" EnableDelete="True" EnableInsert="True"
         ConnectionString="name=HARVESTEntities" Includ="M_EMPRESAS, M_TARIFAS, M_TIPO_ACCESO_TARJETA">
    </asp:EntityDataSource>

More about Include property you can find here:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.entitydatasource.include(v=vs.110).aspx

I hope this helps.

Regards,
Radoslav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Alex Jimenez
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or