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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:38:53+00:00 2026-05-15T23:38:53+00:00

I think I’m missing something very simple here. I have an EF4 ObjectContext that

  • 0

I think I’m missing something very simple here.

I have an EF4 ObjectContext that contains an ObjectSet of type Thing, which is mapped to a table in my database called Things. If I add a Thing to the Things ObjectSet, that Thing is not visible in Things until I call SaveChanges() on the ObjectContext.

So, in the following test fixture, AddToThings_AddsItemsToContext_WithSaveChanges passes but AddToThings_AddsItemsToContext_WithoutSaveChanges fails:

[TestFixture]
public class Ef4Tests
{
    [SetUp]
    public void SetUp()
    {
        var ef4PocEntities = new Ef4PocEntities();
        ef4PocEntities.DeleteDatabase();
        ef4PocEntities.CreateDatabase();
    }

    // this test passes
    [Test]
    public void AddToThings_AddsItemsToContext_WithSaveChanges()
    {
        var ef4PocEntities = new Ef4PocEntities();
        Assert.AreEqual(0, ef4PocEntities.Things.Count());

        ef4PocEntities.AddToThings(new Thing {Name = "Bob"});
        ef4PocEntities.SaveChanges();
        Assert.AreEqual(1, ef4PocEntities.Things.Count());
    }

    // this test fails
    [Test]
    public void AddToThings_AddsItemsToContext_WithoutSaveChanges()
    {
        var ef4PocEntities = new Ef4PocEntities();
        Assert.AreEqual(0, ef4PocEntities.Things.Count());

        ef4PocEntities.AddToThings(new Thing {Name = "Bob"});
        Assert.AreEqual(1, ef4PocEntities.Things.Count());
    }
}

Is there a way to do what I want? I.e. add Entities to an ObjectSet and have them visible without saving to the database?

  • 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-15T23:38:54+00:00Added an answer on May 15, 2026 at 11:38 pm

    The answer is here: Finding Entity Framework contexts.

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

Sidebar

Ask A Question

Stats

  • Questions 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you loading the same file into the viewer as… May 16, 2026 at 12:04 pm
  • Editorial Team
    Editorial Team added an answer function Obj() { Obj.prototype.M = function() { // do something… May 16, 2026 at 12:04 pm
  • Editorial Team
    Editorial Team added an answer Does anyone have any ideas why the objects aren't getting… May 16, 2026 at 12:04 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Think Design: I have many applications that share the same user database! Other tables
I think that I am having a slow evening but I have a question
I think that *something and * something are different. What does the additional white
Think that says it all?
Think Global, Act Local That's what they tell you, however during all my time
Think 2 entities OneToOne mapped. Person and Car. A Person can have a Car.
I think I just need someone to show me the obvious. I have a
I think this is not really possible but worth asking anyway. Say I have
I think this is a question that has been asked many times but I
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.