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

  • SEARCH
  • Home
  • 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

Related Questions

I have a query in linqtosql that returns a LabelNumber: var q = from
Given the following table structure, how can I use a Linq query to return
I have a List of X items. I want to have LINQ query that
I have just started Entity Framework & linq and write this query var query
From a WindowsPhone7 application I need to query a web service by sending a
I have a result set, say clientList. And I want to make sure that
I have two tables in my database Table:Documents Id (int), DocName (nvarchar) ---------------------------- Table:AccessLogs
I am working on a search web page for my site. The requirements state
I generally use List<T> for collections. But if I need a fast lookup on
OK, first my simple Domain Model is 2 classes with a one-to-many relationship, a

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.