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

Grid Hierarchy using EntityDataSource

6 Answers 199 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Seth
Top achievements
Rank 1
Seth asked on 10 Jun 2009, 02:57 PM
How do I need to configure my RadGrid and EntityDataSource to get them to work with hierarchy? I got this to work with LinqToSql but it doesn't seem to work for me with EntityDataSource. I currently have:

<telerik:GridTableView Name="ListItems" DataKeyNames="Id, Parent.Id" DataSourceID="ListItemsDataSource" ... runat="server">
<ParentTableRelation><telerik:GridRelationFields DetailKeyField="Parent.Id" MasterKeyField="Id" /></ParentTableRelation>

<asp:EntityDataSource ID="ListItemsDataSource" ContextTypeName="Blah.Bah" EntitySetName="ListItem" Include="Parent" Where="it.Parent.Id == @ParentId" OrderBy="it.SortOrder" ... runat="server">
<WhereParameters>
 <asp:Parameter Name="ParentId" Type="Int32" />
</WhereParameters>                    
</asp:EntityDataSource>

I'm pretty sure my problem is with the where parameter. It's not hooking into the Grid to fiter the results right. With LinqToSql the DataKeyNames and where paramenters could be identical and it worked, but with entities the DataKeys need to have a dot in them referencing the next object, and you can't put a dot in the parameter name of the where parameter used to filter the datasource. I've tried a bunch of different combinations of ParentId / Parent.Id but I can't seem to get my hierarchy to select with results filtered by the parent record.

If y'all would be kind enough to tell me what time it is or post an example of a grid with hierarchy using two EntityDataSource controls I'd be mighty appreciative. I am also using Automatic CRUD operations on these EntityDataSource controls so I don't think using a fully custom select is going to work, with LINQ I had to use Where.

bd



6 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 15 Jun 2009, 01:29 PM
Hi Seth,

Looking at a live demo of RadGrid hierarchy, you can see the three levels of nested tables use different data source objects each with its own parameter.

We, in the same manner, suggest you to use a different data source object for the parent MasterTableView (one withouth WHERE parameters) and another one for the detail table, specifying as parameter a field from the MasterTableView's data source. The MasterTableView's DataKeyNames would include the primary key of the parent data source, and the nested GridTableView's DataKeyNames would include the primary keys for its own data source.

Sincerely yours,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Seth
Top achievements
Rank 1
answered on 15 Jun 2009, 04:32 PM
I ended up solving my problem by changing the parameter in the where clause of my detail table datasource to a SessionParameter instead of a regular asp:Parameter. For whatever reason on my linq datasources this didn't need to be a session parameter but for my grid using entitydatasources it did.

Seth
0
Susan
Top achievements
Rank 1
answered on 19 Jul 2011, 03:42 PM
How about an example where the where clause is based on the parent record Id which is obtained from the parent and not a session variable?
0
Andy
Top achievements
Rank 1
answered on 04 Dec 2013, 03:50 PM
Hi!
Could you please provide a working example of using Entity Data Sources with hierarchical grid using Parameter instead of SessionParameter for filtering detail tables (as Susan wrote)?
Thanks!
0
Antonio Stoilkov
Telerik team
answered on 09 Dec 2013, 09:22 AM
Hi Andy,

In order to implement a scenario using RadGrid Hierarchy and EntityDataSource you could take the code from our demos and swap the SqlDataSource controls with EntityDataSource and rename the SessionParameter to Parameter and remove the SessionField property as shown in the example below.
<%--<asp:SqlDataSource ID="SqlDataSource3" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Order Details] where OrderID = @OrderID"
    runat="server">
    <SelectParameters>
        <asp:SessionParameter Name="OrderID" SessionField="OrderID" Type="Int32"></asp:SessionParameter>
    </SelectParameters>
</asp:SqlDataSource>--%>
<asp:EntityDataSource ID="EntityDataSource3" runat="server" ConnectionString="name=NorthwindConnectionStringEntities" DefaultContainerName="NorthwindEntities" EnableFlattening="False" EntitySetName="OrderDetails" Where="it.OrderID = @OrderID">
    <SelectParameters>
        <asp:Parameter Name="OrderID" Type="Int32" />
    </SelectParameters>
</asp:EntityDataSource>

You could try implementing the desired functionality and if you have any additional questions related to RadControls please do not hesitate to contact us again.

Regards,
Antonio Stoilkov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Andy
Top achievements
Rank 1
answered on 09 Dec 2013, 04:49 PM
Thanks, Antonio!
I guess EntityDataSource control also needs to have AutoGenerateWhereClause="true", otherwise it throws an exception
Tags
Grid
Asked by
Seth
Top achievements
Rank 1
Answers by
Veli
Telerik team
Seth
Top achievements
Rank 1
Susan
Top achievements
Rank 1
Andy
Top achievements
Rank 1
Antonio Stoilkov
Telerik team
Share this question
or