我有它返回一個衍生財產的部分類:。包含部分類的派生屬性?
public partial class Consultation
{
public string Name
{
get
{
string n = string.Empty;
n += employee.FirstName;
n += " " + employee.LastName;
return n;
}
}
}
在商業邏輯層功能我返回這些實體的名單:
using (var Context = new MMEntities())
{
var cons = Context.Consultations;
return cons.ToList();
}
在.aspx頁面中我有一個數據綁定它採用了實體的衍生屬性控制:
DataTextField="Name"
然而,在編譯的時候,我得到:
The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
我明白我的ObjectContext已被處置,因爲我已將它包裝在'Using'語句中。
我的問題是:如何在返回方法中包含(急切加載)派生的Name屬性? .include方法只適用於導航屬性,我不想長期存在ObjectContexts。
非常感謝......
我無法從你的代碼中瞭解'employee'是否是'Consultation'的依賴類。在這種情況下,我相信你也應該加載它。你能從「Consultation」發佈更多的代碼嗎? – 2012-04-16 07:24:27