c# - Getting last item in tree hierarchy -


I have a menu which supports many levels of hierarchy. I have a function to get the last item in the tree Created and its ID is returned I need this ID, so I can hide the down arrow on the management page.

While this works, I spent 2 days trying to find a LINQ way to do the same thing. So my questions are:

- Is it possible to do this completely in LINQ mode? - If so, how?

My model for Menu Itam looks like this:

  Public partial class menuItem {Public MenuItem () {this.ChildMenuItems = new HashSet & lt; MenuItem & gt; (); } Public Entity ID {Receipt; Set; } Public INITIMIP ID {Receipt; Set; } Public int MenuId {get; Set; } Public String DisplayText {get; Set; } Public string controller {get; Set; } Public string action {get; Set; } Public taps qualified & lt; Int & gt; Parent menu item {receive; Set; } Public ANT rank {receive; Set; } Public Virtual MenuItemType MenuItemType {get; Set; } Public Virtual Menu Menu {Received; Set; } Public virtual iconging & lt; MenuItem & gt; Child menu item {receive; Set; } Public Virtual MenuItem ParentMenuItem {get; Set; }}  

and my recursive function looks like this:

  public static GetLastMenuItemId (list> menuItem> menuItems) {foreach ( Item orderbars in menu menu menu item (mi = & gt; mi.Rank)) {lastId = menuItem.Id; If (menuItem.ChildMenuItems.Any ()) {GetLastMenuItemId (menuItem.ChildMenuItems.ToList ()); }} Previous IID; }  

Additionally, my menu tree currently looks like this:

  Categories: 8 guardian: n / a admin: 1 guardian: n / A Managed Menu: 2 Parent: 1 Manage Menu: 7 Parent: 2 ------------: 5 Parent: 2 Menu: 3 Parent: 2 Menu Item Type: 4 Parent: 2 menu items: 6 Parent: 2 Manage: 9 Parents: 1 Click Manage: 10 Parents: 1 Comment Manage: 11 Parents: 1 Manage Images: 12 Parents: 1 Management No Rating: 13 Guardian: 1  

I will add a function to my menu item which Checks the status of the current menystem in the collection of the child menu item of the parent menu.

Public List & lt; MenuItem & gt; Flatbed childnode {{var ret = new list & lt; MenuItem & gt; (); Exotic hair (hair items in hair items) {ret.Add (item); If (itemChildmenuimes! = Null) {rate.advertisement (itemized flatbed childnodes); }} Return writ; }} Public bool isLastChild {get {if (ParentMenuItem == blank) // return false if we do not have any parent (this is the root node) return false; Other // Correct Return Iff we are the last child in the parents' parents collection (parents). Flared childnode. Toolist () Indexoff (this) == (parent menu itam. Flatbed childnode.tostist (calculation - 1)); }}

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -