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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:40:23+00:00 2026-06-17T15:40:23+00:00

I have a little program that uses ObjectListView to visualise the database information. Currently

  • 0

I have a little program that uses ObjectListView to visualise the database information. Currently I am trying to add items and keep getting The operation cannot be completed because the DbContext has been disposed. Which is highlighting the olvEntityTypes.AddObject(et); line below.

Code:

string typeName = tbTypeName.Text;
string desc = tbDesc.Text;

EntityTypes et;
using (FCERTSModelContainer db = new FCERTSModelContainer())
{
    // Create and save new row for the EntityTypes table.
    et = new EntityTypes { EntityTypeName = typeName, Description = desc };
    db.EntityTypes.Add(et);
    db.SaveChanges();

    olvEntityTypes.AddObject(et);
}
  • I suspected that SaveChanges() might also be closing the context, but trying to add the object before saving changes still throws the same error.
  • Putting olvEntityTypes.AddObject(et); outside of the using block is also a failure.
  • If I query the database with something like the following, no errors are thrown;

Code:

var query = from ent in db.EntityTypes
            orderby ent.EntityTypeName
            select ent;

olvEntityTypes.SetObjects(query);

So I’m at a bit of a loss now as to why this is throwing errors and how to fix it.

  • 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-17T15:40:24+00:00Added an answer on June 17, 2026 at 3:40 pm

    It turns out the problem was the initial setting of objects for the objectlistview. I was using this piece of code;

    var query = db.EntityTypes.OrderBy(eg => eg.EntityTypeName);
    olvEntityTypes.SetObjects(query);
    

    Which works fine, but is in a different using block in my codebase and as such, a completely different DbContext.

    If I convert the query to a List and then call SetObjects() the entire program works without fault.

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

Sidebar

Related Questions

I have a client-server program that uses sockets to transfer information in a stateful
I have this little part of a program that uses a JComboBox to select
I have little program creating a maze. It uses lots of collections (the default
I'm writing a program in C that uses threads to add up numbers from
Assume that I have the following little console application which uses Entity Framework 5:
Hey guys, I'm getting a really strange error. I have a program that needs
Sometimes it's handy to mock up something with a little C program that uses
I am using vb.net 2010 and I have created a program that uses sockets
I have a little bash program that calls a webservice that returns JSON data.
I have a c++ program that uses several very large arrays of doubles, and

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.