【问题标题】:Undelete an entity marked as EntityState.Delete?取消删除标记为 EntityState.Delete 的实体?
【发布时间】:2010-12-17 23:45:55
【问题描述】:

我先说代码吧:

Dim Contact = Context.Contacts.Include("Phones")
Dim phone = Contact.Phones(0)
Contact.Remove(phone)

我现在如何刷新上下文,取消上次删除关系?

我试过了:

Context.Refresh(RefreshMode.StoreWins, phone) 'Doesn't recover the relation
Context.Refresh(RefreshMode.StoreWins, _
    ObjectStateManager.GetObjectStateEntries(EntityState.Deleted))

最后一个抛出 InvalidOperationException: 要刷新的对象集合中索引 0 处的元素具有空 EntityKey 属性值或未附加到此 ObjectStateManager。

重要 表结构:

联系人:名字、姓氏
电话:号码、备注
联系人电话(多对多):ContactId (导航), PhoneId (导航)

【问题讨论】:

    标签: entity-framework many-to-many entity-relationship navigation-properties


    【解决方案1】:

    由于我认为这是一个错误,因此我将其报告给 Microsoft,请投票并分享您的想法:http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=513174

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多