So I have a header table, Client, and each client have some customer.
I am using entity framework to query the data.
When the TreeView display, it will only show Clients, then until user Expands the Client node, it will query its Customers.
Is it possible to do this in MVVM + Linq?
I could do something dynamic, like click on first node and fire event for query, dynamic add tree item etc.
But I want to know if that’s possible to do it in easier way?
Like by take advantage of lazy loading with Linq, databinding etc? Is it possible?
Is it possible, absolutely, but how you do it depends on a lot of different factors which are specific to your project.
What I would do is create a custom
TreeViewItemclass that takes your entity (probably via the constructor) and then when it’sItemsproperty is called, it could call your entity’sClientsnavigation property. If you have lazy loading properly configured, it would be here that the actual database query happened.If you had 10 nodes, and the user only expanded node 2, then only that node’s query would ever fire.