我創建了ASP.NET Web應用程序(以使用WCF數據服務)並添加了對http://services.odata.org/Northwind/Northwind.svc的服務引用。創建一個網頁(.aspx)並添加一個GridView和Button控件。錯誤「試圖跟蹤實體或複雜類型失敗,因爲實體或複雜類型」
寫了下面的代碼:
protected void Button1_Click(object sender, EventArgs e)
{
var o = new NorthwindSvcRef.NorthwindEntities(new Uri("http://services.odata.org/Northwind/Northwind.svc"));
//The following works fine
//------------------------
//var q = o.Customers.Where(c => c.City == "London").ToList();
//GridView1.DataSource = q;
//GridView1.DataBind();
//Following does not work
//-----------------------
var q = o.Customers
.Where(c => c.City == "London")
.Select(c => c);
DataServiceCollection<Customer> oCustomers = new DataServiceCollection<Customer>(q);
GridView1.DataSource = oCustomers;
GridView1.DataBind();
}
一旦我執行上面的代碼中,我遇到了以下錯誤:
An attempt to track an entity or complex type failed because the entity or complex type 'NorthwindSvcRef.Customer' does not implement the INotifyPropertyChanged interface.
誰能幫助我在這?
在此先感謝
您使用的是什麼版本的WCF數據服務?簡而言之,DataServiceCollection要求您提供它的實體實現數據綁定接口= INotifyPropertyChanged。添加服務引用應該爲您負責,但只有某些版本才能正確執行此操作。 –
我正在使用Visual Studio 2010 Ultimate(與目標框架4.0) – user203687