我创建了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