外国实体的 ObjectDisposedException

ObjectDisposedException on Foreign entity

我是 Linq to Sql 的新手,我遇到了有关访问外国实体的问题。 这是相关的数据库:

这是我的部分 class :

public partial class MyClass
{
    public string ProducerAffix
    {
        get { return Producer.Affix; }
    }
}

以及生成与 ProducerId 外键相关的 Producer 属性 的 dbml 设计器文件:

[global::System.Data.Linq.Mapping.AssociationAttribute(Name="Person_MyClass1", Storage="_Person1", ThisKey="ProducerId", OtherKey="Id", IsForeignKey=true)]
    public Person Producer
    {
        get
        {
            return this._Person1.Entity;
        }
        set
        {
            Person previousValue = this._Person1.Entity;
            if (((previousValue != value) 
                        || (this._Person1.HasLoadedOrAssignedValue == false)))
            {
                this.SendPropertyChanging();
                if ((previousValue != null))
                {
                    this._Person1.Entity = null;
                    previousValue.MyClass.Remove(this);
                }
                this._Person1.Entity = value;
                if ((value != null))
                {
                    value.MyClass.Add(this);
                    this.ProducerId = value.Id;
                }
                else
                {
                    this.ProducerId = default(System.Guid);
                }
                this.SendPropertyChanged("Producer");
            }
        }
    }

访问 MyClass 的 Affix 属性 时,抛出 ObjectDisposedException... 访问 属性 时是否需要打开 Datacontext?

我读了这个 post LINQ to SQL ObjectDisposedException on entity that never asked for 但真的很想避免创建 ViewModel... 还有其他解决方案吗?

非常感谢!

编辑

根据 JAT 的回答,我尝试使用 DLO,但真的不知道如何从中 return 我的外国价值...我找到了这个教程 (http://www.codeproject.com/Articles/37857/Optimizing-LINQ-Queries-using-DataLoadOptions),我有吗然后写一个查询?

public string Affix
    {
        get
        {
            using (var db = new DBDataContext())
            {
                var dlo = new DataLoadOptions();
                dlo.LoadWith<Person>(p => p.Affix);
                db.LoadOptions = dlo;
                ...
                return Producer.Affix;
            }
        }
    }

对于那些以后可能遇到同样问题的人,我终于找到了这是从哪里来的。 当我添加我的 Person 和我的 MyClass 时,我使用了这个函数:

public static Person Add(Person person)
{
    using (var db = new DBDataContext())
    {
        db.Person.InsertOnSubmit(person);
        db.SubmitChanges();
        return person;
    }
}

删除 "using" 对我有用,现在我可以访问我的外键实体。 我真的不明白为什么,因为我读到 "using" 是一个比 "new" 更好的解决方案,因为关闭问题,但似乎它不能正常工作,所以我删除了它。

public static Person Add(Person person)
{
    var db = new DBDataContext();

    db.Person.InsertOnSubmit(person);
    db.SubmitChanges();
    return person;

}