I use Entity Framework Core 2.2. It does me a solid by constructing the entire hierarchy from the database without me asking it to. That said, your TreeList actually binds to a Flat structure. Your model definition then defines how the hierarchy is built.
Do you have an example of how you use EF with your TreeList? Do you have tools or a method that I could use to convert what I get from EF over to what your control needs?
I have a self-referencing Group table:
- Id
- ParentId
- Name
- Description
ParentId references Id
@(Html.Kendo().TreeList<GsiPortal.Models.Group>() .Name("treelist") .Columns(columns => { columns.Add().Command(c => { c.Custom().Text("Details").Name("detailButton").Click("toDetails"); }).Width(120); columns.Add().Field(e => e.Name).Width(220).TemplateId("icon-template"); columns.Add().Field(e => e.Description).Width(220); columns.Add().Command(c => { c.Custom().Text("Create").Name("createButton").Click("toCreate"); }).Width(120); }) .Selectable(selectable => selectable.Mode(TreeListSelectionMode.Single)) .DataSource(dataSource => dataSource .ServerOperation(false) .Read(read => read.Action("IndexJson", "Groups").Data("readParams")) .Model(m => { m.Id(f => f.Id); m.ParentId(f => f.ParentId); m.Expanded(true); m.Field(f => f.Name); m.Field(f => f.Description); } ) .Events(events => { events.Error("onError"); }) )) <script> var groupId = Number(@(ViewBag.GroupId)); function readParams() { return { id: groupId }; } function toDetails(e) { e.preventDefault(); var dataItem = this.dataItem($(e.currentTarget).closest("tr")); if (dataItem != null) { window.location.href = '@Url.Action("Details", "Groups")/' + dataItem.Id; } } function toCreate(e) { e.preventDefault(); var dataItem = this.dataItem($(e.currentTarget).closest("tr")); if (dataItem != null) { window.location.href = '@Url.Action("Create", "Groups")/?parentId=' + dataItem.Id; } } function onError(e) { alert(e.toString()); } </script>