Refresh entity instance with DbContext

后端 未结 3 2169
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 15:57

With EF4 CTP5 DbContext, what is the equivalent of this

    public void Refresh(Document instance)
    {
        _ctx.Refresh(RefreshMode.StoreWins, instance         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 16:10

    I found that the reload fails on proxy entities that have navigation properties.

    As a work around, reset the current values and then reload like this:

    var entry =_ctx.Entry(instance);
    entry.CurrentValues.SetValues(entry.OriginalValues); 
    entry.Reload();
    

提交回复
热议问题