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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:17:08+00:00 2026-05-11T00:17:08+00:00

Firstly, let me set out what I’d like to do. Assume I have three

  • 0

Firstly, let me set out what I’d like to do. Assume I have three types of EntityObject, MetaData, Data1 and Data2. MetaData is, as one would expect, has a reference to one instance each of Data1 and Data2. Now, for each MetaData, I can calculate a value.

So far so simple. Now, I would like the user to play around with various combinations of Data1 and Data2, and see what values they can get. This obviously requires creation of instances of MetaData. Now, if I don’t want to cluter the database with all these entries of MetaData, then I’d like to create the entity objects in the in-memory context without calling a SaveChanges() to write it back to the DB. However, this presents a problem in that whenever I try to access the Data1 and Data2 references of the in-memory MetaData, I end up with the following exception:

InvalidOperationException is unhandled

The source query for this EntityCollection or EntityReference cannot be returned when the related object is in either an added state or a detached state and was not originally retrieved using the NoTracking merge option.

If I do as suggested, and ‘committ’ the object to DB, I end up with the clutter problem.

Anyhow, the guilty code looks something like this:

MetaData temp = MetaData.CreateMetaData(0);  MetaData.Data1 = <existing Data1 from context>; MetaData.Data2 = <existing Data2 from context>;  //Exception here if (!MetaData.Data1Reference.isLoaded)     MetaData.Data1Reference.Load(); 

It seems this guy had a similar problem.

  • 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. 2026-05-11T00:17:09+00:00Added an answer on May 11, 2026 at 12:17 am

    IsLoaded is only relevant for properties of instances which have been materialized from a database. As you’ve discovered, it does not return useful information for instances which have not been materialized from a database.

    Therefore, you should change the way you test whether or not you want to call Load(). If you know that you will be working with instances of MetaData which you have only created in memory and not materialized from a database, then you could write code like this:

    if ((temp.EntityState != System.Data.EntityState.Added) &&      (!temp.Data1Reference.IsLoaded)) temp.Data1Reference.Load(); 

    I’m glossing over some subtleties, here. For starters, EntityState is declared with FlagsAttribute, so it can contain Added without being equal to Added. Also, none of this is necessary if Data1Reference is non-null, so you might just want to test for that first. The point is, you can write code which suits your situation, but it must account for the full state of temp, not just its properties.

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

Sidebar

Related Questions

Firstly, I do not have any malicious intent out of this question. I would
Let's say I have some email: some_email@yahoo.com . Firstly I would want to remove
Firstly let me say I believe immutability is one of the best things one
Firstly the only thing I have available is powershell. I have figured out how
Firstly, let me start by saying that I haven't ever directly used SQL views.
Firstly, let me say that I've been searching the Internet, rewriting scripts and I
Firstly: I am totally a newbie for this kind of work. I have a
Firstly, Modifying may be the wrong term, I see a few people have posted
Firstly, let me introduce general architecture of a project. It is hierarchical. We develop
Firstly, let me say that I've been on this issue for pretty much 2

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.