EntityFramework ObjectContext 刷新问题
我有 DataContext.Refresh 方法:
public void RefreshDataSource()
{
_entities.Refresh(RefreshMode.ClientWins,Departments);
}
和可观察的集合:
public ObservableCollection<Department> Departments
{
get
{
if (_departments == null && _entities != null)
{
_entities.Departments.Include("Drivers").ToArray();
_departments = new EntityObservableCollection<Department>(_entities.Departments);
}
return _departments;
}
}
如果我更新上下文之外的记录,我只能看到更改的记录,但看不到插入和删除的记录。为什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为
Refresh
不会查找新记录。它获取您已有的记录并用当前值更新它们。它也可能不处理已删除的记录,特别是如果您使用将您的状态视为更重要的ClientWins
策略。Because
Refresh
doesn't look for new records. It takes records you already have and updates them with current values. It also probably doesn't handle deleted records especially if you useClientWins
strategy which takes your state as more important.