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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:01:05+00:00 2026-06-17T19:01:05+00:00

For example, say I am either creating or fetching some entities that I later

  • 0

For example, say I am either creating or fetching some entities that I later plan to insert, update, or discard:

foreach (var foo in foos) {
    if (foo.condition)
        _myEntityCollection.Add(new Some_Entity_Type());
    else
        _myEntityCollection.Add(dc.Some_Entity_Types
          .Where(t => t.ID == someID).FirstOrDefault());
}

When it comes time to, say, revert, I may do this:

// Exception gets thrown here if entity didn't exist in data context
_myEntityCollection.ForEach(t => dc.Refresh(RefreshMode.OverwriteCurrentValues, t));

I want to be able to iterate through _myEntityCollection and determine if the entity was one I fetched, or if it was a new one.

  • 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-17T19:01:06+00:00Added an answer on June 17, 2026 at 7:01 pm

    You could use the object state manager to test if the object context is aware of a specific entity.

    var objectStateManager = context.ObjectStateManager;
    
    ObjectStateEntry temp;
    var result = objectStateManager.TryGetObjectStateEntry(myEntity, out temp);
    

    UPDATE

    The code from above works for the Entity Framework but the question concerns LINQ to SQL. You could try to inspect the ChangeSet returned by DataContext.GetChangeSet(). It contains three lists for added, deleted and updated entities.

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

Sidebar

Related Questions

i have problem use link_to_remote link_to_remote document example say link_to_remote Delete this post, :update
For example lets say I have a JSON object that contains states and cities.
To use as an example: lets say that I have 2 EditText s and
As an example say I have a class foo that does not have a
Say that you want to do some fancy formatting of some tabular output from
Example: say I want to open a file. If I get a FileNotFoundException ,
Currently I have a timestamp for example say, 2012-06-23 14:24:07.975 and two times -
Is intercontainer communication possible within Apache tomcat? For example: Say you have 2 rest
can you get the last or newly added element in std::set? for example say
for example lets say your pulling data from somewhere and you put it in

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.