请教:未处理InvalidOperationException,无法返回此 EntityCollection 或 EntityReference 的源查询。
private void suppliersList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
this.supplier = listBox1.SelectedItem as Supplier;
this.northwindContext.LoadProperty<Supplier>(this.supplier, s => s.Products);
this.productsInfo = ((IListSource)supplier.Products).GetList();
productsList.DataContext = this.productsInfo;
}
===上面是源代码===
错误出现在当supplier表添加新记录并选择该记录时,
this.northwindContext.LoadProperty<Supplier>(this.supplier, s => s.Products);该行代码出错,
提示“未处理InvalidOperationException:当相关对象处于 added 状态或 detached 状态时,并且最初并非使用 NoTracking 合并选项进行检索时,无法返回此 EntityCollection 或 EntityReference 的源查询。”