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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:09:20+00:00 2026-06-10T23:09:20+00:00

I’m having difficulty with ObjectContext.LoadProperty (EF 4 Database First) (both the string and expression

  • 0

I’m having difficulty with ObjectContext.LoadProperty (EF 4 Database First) (both the string and expression overloads exhibit the same behavior for me). Given the following simple schema:

Product
--------------
ProductId (pk)
...

Order
--------------
OrderId (pk)
...

OrderItem
--------------
OrderId (pk, fk Order),
ItemNumber (pk),
ProductId (fk Product)
...

Because I’ve found it to perform better than Includes in my particular scenario, I’m using LoadProperty to populate the related entity. For example,

Order ord = context.Orders.Where(o => o.OrderId = 1).FirstOrDefault();

context.LoadProperty(ord, o => o.Items); // Items is the navigation property name for the
                                            OrderItem -> Order relationship

foreach(var i in ord.Items)
{
    context.LoadProperty(i, oi => oi.Product);
}

This has been in place for some time and has worked (as you’d expect) just fine. However, this morning we started encountering a scenario where even after calling LoadProperty, i.Product was still null. i.ProductId is valid and I can even load the product explicitly like so:

var product = context.Products.Where(p => p.ProductId == i.ProductId).FirstOrDefault();

But LoadProperty won’t load the object. No exception is thrown, it just simply doesn’t load it. I’ve also tried specifying MergeOptions.OverwriteChanges (even though there aren’t any), and the results have been predictably the same.

What could cause ObjectContext.LoadProperty to fail silently in this manner?

  • 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-06-10T23:09:21+00:00Added an answer on June 10, 2026 at 11:09 pm

    I’ve discovered that this appears to be an issue (if not an outright bug) with the way EF’s LoadProperty function works.

    The OrderItem and Product tables had values for ProductId that differed either by case, trailing spaces, or both. Given SQL Server’s default collation, this was legal and referential integrity was maintained. This is why queries for the product worked, but it seems that EF was doing key comparisons internally somewhere and being more stringent about these values.

    If you encounter this issue yourself, you can check for trailing spaces by using the T-SQL DATALENGTH function in your query and you can compare case by using a different collation.

    For example, you can see discrepancies in my above model using this:

    select
        *
    
    from OrderItem oi
    
    join Product p on p.ProductId = oi.ProductId -- default collation; case and 
                                                 -- trailing spaces ignored
    
    where DATALENGTH(oi.ProductId) <> DATALENGTH(p.Product) -- trailing spaces differ
       or oi.ProductId <> p.ProductId COLLATE SQL_Latin1_General_CP1_CS_AS -- case differs
    

    Note that it may be possible to compare both trailing spaces and character casing using collation only; if anyone knows the name of a collation that does such a thing, feel free to edit this answer or post a comment and I’ll update. Until then, this should do what’s necessary.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string

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.