Many to Many in Hierarchical grid and Entity Framework

2 posts, 0 answers
  1. Calsh
    Calsh avatar
    15 posts
    Member since:
    Dec 2012

    Posted 17 Jul 2017 Link to this post

    I have an Entity Framework 6 fluent model in which there is a many to many relationship between an Employee and Teams. The EF model represents the teams that an employee is a member of by an ICollection.

    I'm trying to list employees and their associated teams in a declarative hierarchical grid in which the parent table displays an Employee's details and the detail/hierarchical table displays the teams. I'm trying to figure out if it possible to use the ICollection<Teams> to display the list of teams in the detail grid. I tried numerous ways with various datasourceIds, DataKeynames etc. - and also looked at demos/sample

     

    Outline of code is below:

     

    public partial class Employees
        {
          
            public int EmployeeId { get; set; }
            public string EmployeeFirstName { get; set; }
            public string EmployeeLastName { get; set; }
         
            public virtual ICollection<Teams> Teams{ get; set; }
        }

     public partial class Teams
        {
            [
            public int TeamId{ get; set; }
            public string TeamName{ get; set; }
             public virtual ICollection<Employees> Employees { get; set; }
        }

    <ef:EntityDataSource ID="EntityDataSource1" runat="server" ContextTypeName="EF6Model" EntitySetName="Employees" Include="Teams"></ef:EntityDataSource>

     <telerik:RadGrid ID="RadGrid1" >
      <MasterTableView DataSourceID="EntityDataSource1" DataKeyNames="EmployeeId" >
                        <Columns>
                            <telerik:GridBoundColumn HeaderText="First Name" DataField="EmployeeFirstName">
                            </telerik:GridBoundColumn>

             ...................Employee A data here.......
     
                        </Columns>
                        <DetailTables>
                            <telerik:GridTableView>

                              .................Team 1 that Employe A is a member of here...............

                              .................Team 2 that Employe A is a member of here...............

        .................Team 1 that Employe A is a member of here...............

                            </telerik:GridTableView>
                        </DetailTables>
                    </MasterTableView>
    </telerik:RadGrid>

  2. Calsh
    Calsh avatar
    15 posts
    Member since:
    Dec 2012

    Posted 17 Jul 2017 in reply to Calsh Link to this post

    Posted accidently before finished - cont'd

    I know that this could be done by joining employees and teams in sql/select statements etc. and via various events in code behind - but I am trying to do this declaratively 'via the grid properties' - and can't find any examples online?

    Thanks

Back to Top