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

Multiple Entity Framework 4 Entities & OnNeedDataSource

1 Answer 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard Weeks
Top achievements
Rank 2
Richard Weeks asked on 01 Mar 2011, 06:20 AM
Hi, how can I bind a RadGrid when I need to include details from more than one entity?

I have the following code that runs, definitely brings back data but does not show anything in my grid (with AutoGenerateColumns set to "true"):

protected void MyGrid_OnNeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    using (var context = new MyContainer())
    {
        var d = from data in context.ParentEntity.Include("ChildEntities"
                select new
                {
                    data.ParentProperty, 
                    data.ChildEntity.FirstOrDefault().ChildProperty
                };
  
        this.MyGrid.DataSource = d.ToList();
    }
}

I don't mind admitting my LINQ to Entities knowledge is "ongoing" but you can see what I am trying to do: for every ParentEntity, get me their properties and for every ChildEntity under that, get me their properties as well. I want the grid to display those.

Because the ChildEntity may not necessarilly immediately have a ParentEntity, I can't do a master / detail view with two grids.

Richard

1 Answer, 1 is accepted

Sort by
0
Accepted
Pavlina
Telerik team
answered on 04 Mar 2011, 02:54 PM
Hello Richard,

To display hierarchical data, RadGrid renders one or more detail tables for each item (row) in the MasterTableView. In a multi-level hierarchy, each item of every detail table can have one or more detail tables as well. The level of the grid hierarchy can be arbitrarily deep.

When binding each detail table view, RadGrid fires the DetailTableDataBind event. The argument for a DetailTableDataBind event handler carries all the information you need for binding the detail table, including the table view that should be bound, its parent item, and so on. Please refer to this help article for more information.


I hope this gets you started properly.

Greetings,
Pavlina
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Grid
Asked by
Richard Weeks
Top achievements
Rank 2
Answers by
Pavlina
Telerik team
Share this question
or