title: "Cannot access a disposed object"
body: <p>I have a problem while accessing a association object from linq to sql.
  I have a class Article and User. Each Article has a seller (which is a User) and each user has many Articles. I solved that with an association.</p>
  
  <p>This is how my linq to sql classes looks like:
  <img src="https://i.stack.imgur.com/RdgbR.png" alt="linq to sql classes"></p>
  
  <p>And this is the association:</p>
  
  <p><img src="https://i.stack.imgur.com/fJlZu.png" alt="association"></p>
  
  <p>Here is the code behind the Article.Seller:</p>
  
  <pre><code>[global::System.Data.Linq.Mapping.AssociationAttribute(Name="User_Article", Storage="_Seller", ThisKey="SellerID", OtherKey="ID", IsForeignKey=true)]
  public User Seller
  {
      get
      {
          return this._Seller.Entity;
      }
      set
      {
                     ...
      }
  }
  </code></pre>
  
  <p>Now, when I want to get the Seller of an Article, I get the following error:</p>
  
  <blockquote>
    <p>Cannot access a disposed object. Object name: 'DataContext accessed
    after Dispose.'.</p>
  </blockquote>
  
  <p>The error occurs in the get of seller.</p>
  
  <p>Any ideas how to handle this?</p>
  
  <p>EDIT: Heres' the code where DataContext is used:</p>
  
  <pre><code>public static List&lt;Article&gt; Read()
  {
      using (uDataContext dbx = new uDataContext())
      {
          return dbx.Article.ToList();
      }
  }
  </code></pre>
  
  <p>The list is used as following:</p>
  
  <pre><code>List&lt;Article&gt; articles = ArticleDALC.Read();
  
  foreach (Article article in articles)
  {
      // Exception appears here!
      User seller = article.Seller;
      ....
  }
  </code></pre>