Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Get Hierarchical Data Using Linq2Sql

Get Hierarchical Data Using Linq2Sql

Scheduled Pinned Locked Moved LINQ
databasehelpquestiondata-structures
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    srulyt
    wrote on last edited by
    #1

    What is the best way to retrieve hierarchical data using Linq2Sql? I have a tree of data and i want to pull it out and put it in my own classes. The data is for a menu and I have a menu class which has children which are menu items these children in turn have children etc... I want to pull the whole tree and place it into my own classes. The most logical way i could think of doing this was to have an extension method that can recursively convert EntitySet to List i would then call this from m in DataContext.Menus where m.ID == ID select new Menu(){ Name = m.Name, ID = m.ID, Childen = m.LinqMenuItems.ToChildren()}; The ToChildren would then recursively convert all LinqMenuItems and their Children LinqMenuItems to my MenuItem implementation. The problem with this approach is that I get an error saying ToChildren doesn't have a translation to SQL. Seemingly I cant use my own extension methods in a Linq2Sql query. Any Ideas?

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups