Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 662977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:26:18+00:00 2026-05-13T23:26:18+00:00

How can I write a LINQ query that returns an hierachical anonymous type from

  • 0

How can I write a LINQ query that returns an hierachical anonymous type from a Join?

To clarify what I mean:
With WCF Data Services and Telerik WPF RadTreeView one can easily query and display hierarchical data:

    Dim q = _ctx1.Execute(Of NorthwindDataService.Customers)(New Uri("Customers\?$expand=Orders", UriKind.Relative))
    Dim td As New GridViewTableDefinition
    td.Relation = New Telerik.Windows.Data.PropertyRelation("Orders")
    RadGridView1.ChildTableDefinitions.Add(td)
    Dim r = q.ToList
    RadGridView1.ItemsSource = r

I want to join entities from different Data Services and display them in a hierachical grid.

Dim q = From c In _ctx1.Customers.ToList
Join o In _ctx2.Orders.ToList On c.CustomerID Equals o.CustomerID
  Select New With {c.CustomerID,
                       o.OrderId
                      }

The join works.
How can I “Select” an anonymous type with all properties of Customer plus an Orders property,
analogous to what a data service returns, that does directly bind to the grid?

Something like (this is not supported syntax!):
Select New With {c.*,
.Orders = o
}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:26:19+00:00Added an answer on May 13, 2026 at 11:26 pm

    For two different data services you can use LINQ to Objects:

    Dim q1 = _ctx1.Customers.AsEnumerable()
    Dim q2 = _ctx2.Orders.ToList()
    
    Dim q = From c in q1
            Select New With {c.CustomerID,
                             q2.Where(o => o.CustomerID == c.CustomerID)
                            }
    

    Again, apologies in advance for VB.NET syntax errors on my part.

    For one service:

    It’s almost always a mistake to use join in LINQ to Entities or LINQ to SQL.

    The direct analogy to your data services query is:

    Dim q = _ctx1.Customers.Include("Orders");
    

    But you can also project as with your L2E example:

    Dim q = From c In _ctx1.Customers.ToList
            Select New With { c.CustomerID,
                              From o in c.Orders Select o.OrderID}
    

    Apologies in advance for syntax errors; VB.NET is not my forte.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 344k
  • Answers 344k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can make use of java.net.URL and/or java.net.URLConnection. URL url… May 14, 2026 at 5:43 am
  • Editorial Team
    Editorial Team added an answer enlightenment enables real cross platform from Windows CE to WIndows… May 14, 2026 at 5:43 am
  • Editorial Team
    Editorial Team added an answer Easy fix. ANDROID_SDK_HOME path variable set to teh mapped drive… May 14, 2026 at 5:43 am

Related Questions

I am working on a database access layer project and decided to use Linq
How can I use Linq with Dataset.xsd files? I've looked at Linq-to-Datasets and Linq-to-XSD
I have some existing code that retrieves data from a database using ADO.NET that
I just wanted to share this Query class and get your thoughts on it.
Short Question: Basically I am trying to add a scalar property to my entity

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.