我正在努力删除多行。我正在学习并管理新的行和编辑,但似乎不能指甲删除。有人可以帮忙吗?
这就是我所拥有的:
If ViewState("QuoteGroupID") IsNot Nothing Then
Dim GQID As Integer = CInt(ViewState("QuoteGroupID"))
Using db As New quotingSystemDevEntities
Dim QuoteToDelete = (From q In db.QuotesGeneratedV2 Where q.QuoteGroupID = GQID Select q)
db.DeleteObject(QuoteToDelete)
db.SaveChanges()
End Using
End If
我收到错误“无法删除该对象,因为在ObjectStateManager中找不到该对象。”
谢谢你的时间。
If ViewState("QuoteGroupID") IsNot Nothing Then
Dim GQID As Integer = CInt(ViewState("QuoteGroupID"))
Using db As New quotingSystemDevEntities
Dim QuoteToDelete = (From q In db.QuotesGeneratedV2 Where q.QuoteGroupID = GQID Select q)
For Each item In QuoteToDelete
db.Detach(item)
db.Attach(item)
db.DeleteObject(item)
Next
db.SaveChanges()
End Using
End If
答案 0 :(得分:1)
我认为你错过了ObjectContext.Attach方法。尝试使用它。
也可以找到类似的问题Entity Framework Delete Object Problem