7

而不是说话让我用代码说话:

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 处的元素具有 null EntityKey 属性值或未附加到此 ObjectStateManager。

重要 表结构:

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

4

1 回答 1

4

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

于 2009-11-22T01:00:19.657 回答