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

Entity Framework Core 2.2 + Hierarchy

1 Answer 91 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 2
Iron
Iron
Iron
Joel asked on 12 Feb 2019, 11:36 PM

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>

1 Answer, 1 is accepted

Sort by
0
Preslav
Telerik team
answered on 15 Feb 2019, 01:27 PM
Hello Joel,

At this stage, we do not have an example of how to use Entity Framework hierarchy with our TreeList. What I could suggest is to manually flatten the data. To do that, you might be interested in checking these resources:
Generally speaking, there is no recommended way to flatten the data, you could use anything that fits your application requirements.


Regards,
Preslav
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
TreeList
Asked by
Joel
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Preslav
Telerik team
Share this question
or