首页 > 解决方案 > 实体框架 Reload() 错误 无效操作

问题描述

myEntities dc = new myEntities();
...

//i show the table data to user

mainSearchedData = dc.Invoice.ToList();
gvMain.DataSource = mainSearchedData;

//then i change some data in the table(Somewhere else in the code) and save 
//it    
dc.SaveChanges(); //(the change is successfull i can se it in SSMS)

//since if i just use the gvMain.datasource set it wont load the changes 
//that has been made in the tabel i want to reload

dc.Entry(dc).Reload();  <-- This is causing the error

“System.InvalidOperationException:'实体类型 myEntities 不是当前上下文模型的一部分。”

我愿意提供一个没有Reload()如何使实体框架实际加载修改数据的方法的解决方案

标签: c#entity-framework-6

解决方案


推荐阅读