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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:15:22+00:00 2026-05-26T09:15:22+00:00

If I use my entity model in a web project I can navigate to

  • 0

If I use my entity model in a web project I can navigate to the 1-* 1-0.1 nav properties fine…but when I load that exact same object via LinqPad at my oData Service the nav property is always null

…am I doing something wrong?…should it be enabled somehow?

If I load up fiddler and run the query http://odata.site.com/Service1.svc/usda_FOOD_DES(1001)/usda_ABBREV

…it returns the correct result

Thanks,
Steve

  • 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-26T09:15:23+00:00Added an answer on May 26, 2026 at 9:15 am

    I asked myself the same question. I was wondering why the following returned an empty collection:

    Customers.Where(c => c.ID == 1).Single().Orders
    

    The reason is that unlike with Entity Framework’s navigation properties, when you access a property of an OData entity it does not automatically go back to the data source and retrieve any data that is not already present. So when you retrieve an entity from an OData feed, by default it does not include the linked entities, so you get an empty IEnumerable<T> for one to many or many to many navigation properties or null for single entity navigation properties.

    You would expected the above query to translate to:

    http;//odata.sample.com/MyODataFeed.svc/Customers(1)/Orders

    Which would return all orders, but instead it translates to this (to see the query in LINQPad, click the SQL button above the results pane):

    http;//odata.sample.com/MyODataFeed.svc/Customers(1)

    This is because the .Orders at the end is not within any extension method, and so does not participate in the construction of the IQueryable. Therefore it is not reflected in the URL that is constructed from the query and is not included in the result set.

    So how would you get just the orders of customer 1? You could try and work around the issue by using the following query:

    Customers.Where(c => c.ID == 1).Select(a => c.Orders)
    

    This should cause the .Orders property to be included in the query. Unfortunately, a .Select(...) without projecting the result into an anonymous method (i.e. new { ... }) is not allowed and throws a NotSupportedException: The method 'Select' is not supported. What a shame. So what about:

    Customers.Where(c => c.ID == 1).Select(a => new { c.Orders })
    

    That doesn’t produce the expected result and instead performs the following query:

    http;//odata.sample.com/MyODataFeed.svc/Customers(1)?$expand=Orders&$select=Orders

    I don’t understand why this is simply not translated to /Customers(1)/Orders. In any case, it puts the list of orders inside an unneeded wrapper class which can be quite annoying, but it works, and it was the closest I could get to retrieving just the content of a navigation property.

    The method I prefer is to include all the orders with each customer, as so:

    Customers.Expand("Orders").Where(c => c.ID == 1).Single().Orders
    

    This produces the following query:

    http;//odata.sample.com/MyODataFeed.svc/Customers(1)?$expand=Orders

    This works, but has the disadvantage of including all the customer details, which we may not need. Also, the string-yness of .Expand(...) is problematic – it is has weak typing so it won’t be verified by the compiler (beware of spelling mistakes), not all refactoring tools will refactor it too, finding all usages of that property will not include that string in the search result, etc.

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

Sidebar

Related Questions

I want to use Services(WCF/RIA /Web) to take data from Entity Data Model class
I'm trying to use Dynamic Data with a entity model that has Abstract class
Is there any way to use an Entity as a model, and be able
I'm planning to use MS entity framework for new web apps (come on EF
I am developing a rich client application that will use the Entity Framework (with
I'm writing a log parser for an asp.net mvc2 web application. I use Entity
I'm about to start developing a web-based application that I can best describe as
I have a web application where i need to use entity frame work.Actually i
I Am creating a web application and first use Entity Framework. I created Entity
I have a DAL project, with an entity data model context bound with EF

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.