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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:10:06+00:00 2026-05-27T01:10:06+00:00

My model is implemented in an own DLL, where also the generated App.config is

  • 0

My model is implemented in an own DLL, where also the generated App.config is placed. The application itself “had” no App.config. No context was initialized (direct access in DLL only). And i get an error, which was solved by copy the connection string into the application new by hand generated App.config.

This case was a little bit redundant for me and I decided to get the EntityConnection by writing it myself. Now the problematic code, which works with the redundant version and not in the own implementation.

public Discount GetDiscountByOffer(int discountId)
{
    // Own implementation, redundant one without passed connection parameter
    using (context2 = new SalesEntities(Configuration.EntityConnection))
    {
        return context2.Discounts.Single(d => d.ID == discountId);
    }
}

In another class I call this method and assign it to a customer. Also here i make a new context. Code simplified:

    // Own implementation, redundant one without passed connection parameter
    using (context1 = new SalesEntities(Configuration.EntityConnection))
    {
        var customer = GetCustomer(10004);
        customer.ActualDiscount = GetDiscountByOffer(5); // here is the call and 
                                                         // the error
    }

The error ahows that ObjectContext (context1) was closed, what I don’t understand. What has context2 to do with context1? I bet that both share the same reference, but it’s not logical for me. The EntityConnection is also initialized new each time I pass the parameter.

In the redundant version this code works.

  • 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-27T01:10:07+00:00Added an answer on May 27, 2026 at 1:10 am

    Get the object from context2, attach it to context1, then set the customer’s property.

    MSDN explanation:

    http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.attach.aspx

    Read ‘The problems of working with multiple ObjectContext instances’ below:

    http://dotnetslackers.com/articles/ado_net/Managing-Entity-Framework-ObjectContext-lifespan-and-scope-in-n-layered-ASP-NET-applications.aspx#the-problems-of-working-with-multiple-objectcontext-instances

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

Sidebar

Related Questions

I've implemented my own event handler and added it to the selection model of
I'm working on a MVC application in which the Model is implemented using an
I have a QTableView that I implemented with my own model subclassed from QAbstractTableModel
I implemented my own ListCellRenderer for my chat app. I use a JList to
I've implemented my own copy of the model view presenter pattern (in vein of
Here's the model I implemented: public class LoginSession { private static final Gson gson
I've implemented as_json in the parent model as follows: def as_json(options = {}) options[:include]
How should model class's equals and hashcode be implemented in Hibernate? What are the
I have a model which has a certain behaviour implemented. class X { ....
I have a somewhat complex data model in my iPad application (an OpenGL drawing

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.