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

Many to Many in Hierarchical grid and Entity Framework

1 Answer 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Calsh
Top achievements
Rank 1
Calsh asked on 18 Jul 2017, 12:19 AM

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>

1 Answer, 1 is accepted

Sort by
0
Calsh
Top achievements
Rank 1
answered on 18 Jul 2017, 12:27 AM

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

Tags
Grid
Asked by
Calsh
Top achievements
Rank 1
Answers by
Calsh
Top achievements
Rank 1
Share this question
or