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 3271544
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:44:18+00:00 2026-05-17T18:44:18+00:00

I am trying to query a single entity in a database with a DataServiceQuery.

  • 0

I am trying to query a single entity in a database with a DataServiceQuery.
The entity I am trying to load has relations to a graph of other entities that I want to load as well. MSDN describes here and here that I can load my referred entities using either DataServiceQuery<TElement>.Expand or DataServiceContext.LoadProperty.

This works fine for first degree relations of my entity, but I have a problem loading relations of relations.

Obviously I could call LoadProperty for all second degree relations and loop through all second degree collections, but I was hoping that I could eager load the whole relation graph in a single query. Is that possible?

Edit

Actually loading the second degree relations is not that obvious after all.
The following code fails (domain model changed for clarity):

            var context = DataServiceReference.DataServiceContextFactory.Create();
            var customer = (from c in context.Customers.Expand("Orders")
                                where c.CustomerId.Equals(customerId)
                                 select c).First();
            foreach (var order in customer.Orders)
            {
                context.LoadProperty(order, "Products");

The last line above throws InvalidOperationException: “The context is not currently tracking the entity.”.
I use self-tracking-entities. Could this error be related to STE?

How would I load second degree relations in any way?

Solution edit

It turns out that DataServiceQuery<TElement>.Expand uses a different path syntax compared to ObjectQuery<T>.Include. The former uses slash as path separator the latter uses dot. Can anyone explain why the syntax is inconsistent and where I can find documentation of the Expand path syntax?

  • 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-17T18:44:19+00:00Added an answer on May 17, 2026 at 6:44 pm

    The DataServiceContextFactory is your own class, right? (since that’s not how you typically instantiate a DataServiceContext). Assuming it ends up creating a normal DataServiceContext instance then the way to eager load multiple levels is just to specify the multiple levels in you Expand call. So for example:
    context.Customers.Expand(“Orders/Products”)
    Will return you all customers, their orders and all the products for those orders.
    For LoadProperty to work, please make sure that on your DataServiceContext the property MergeOption is set to one of the options which allow tracking.
    Note that the client side tracking has nothing to do with the server side EF tracking (it’s a separate code on a separate machine technically).
    You can verify that the context tracks the entity in question by trying to call
    context.GetEntityDescriptor(myEntityInstance)
    If it returns non-null, the context is tracking the entity and LoadProperty should work.

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

Sidebar

Related Questions

I'm trying to retrieve a single entity from a Linq2Sql query, but I'm having
I'm trying to write a query that will pull back the two most recent
We are trying to load some entities into our classes on startup. The entities
I'm building a database that makes use of lots of many-to-many relations. For example,
Before trying to query the AD server I would like to check if it
I'm trying to do query result pagination with hibernate and displaytag, and Hibernate DetachedCriteria
I'm trying to optimize query performance and have had to resort to using optimizer
I'm trying write a query to find records which don't have a matching record
When trying to enter a SQL query with parameters using the Oracle OLE DB
I' trying to use a Linq query to find and set the selected value

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.