我有两张桌子:Main和Vendors。
Main table:
MainID (PK)
Name
Address
...
Vendors table:
VendorID (PK)
MainID (ForeignKey)
Code
....
Vendors表格中的数据显示在ListBox控件中。
当我尝试Vendors使用 ListBox 控件中的按钮从表中删除一行时,出现以下错误:
无法移除尚未附加的实体。
删除按钮代码为:
Dim button = TryCast(sender, Button)
If button IsNot Nothing Then
Using db As New theContext.theContext("Data Source=isostore:/theDB.sdf")
Dim RecordToDelete As Vendors = TryCast(button.DataContext, Vendors)
VendorsRecords.Remove(RecordToDelete)
db.VendorsRecords.DeleteOnSubmit(RecordToDelete)
db.SubmitChanges()
End Using
End If