0

在 LINQ 中,我试图编写一个查询,一旦单击按钮,就会从数据库表中删除一条记录,即“Amendments_Awaiting_Approval”。将根据在文本框中输入的值找到并删除该行。到目前为止我有这个:'你的输入字符串

Dim parseRef As String = txtReferenceCode.Text

'Convert string to integer value '
Dim deleteRecord As Integer = Integer.Parse(parseRef)

' Query the database for the rows to be deleted. '
Dim deleteModuleChanges = _
    From amendments In db.Amendments_Awaiting_Approvals _
    Where amendments.Amendments_ID = deleteRecord _
    Select amendments

For Each amendment As Amendments_Awaiting_Approval In deleteModuleChanges()
    db.OrderDetails.DeleteOnSubmit(detail)
Next

此段不工作。该页面甚至不会加载,当我将鼠标悬停在 deleteModuleChanges() 部分时,我收到错误“重载解析失败,因为没有可访问的 ElementAtOrDefault 接受此数量的参数”

有任何想法吗?

4

1 回答 1

2

deleteModuleChangesIEnumerable,所以当你添加()到它时,VB.NET 编译器尝试ElementAtOrDefault在该集合上触发扩展方法,没有参数就无法完成。试试那个:

For Each amendment As Amendments_Awaiting_Approval In deleteModuleChanges
    db.OrderDetails.DeleteOnSubmit(detail)
Next

但是,我不知道您为什么要迭代amendment,而是 delete detail。你确定那是你想做的吗?

当然,您必须提交更改:

db.SubmitChanges()
于 2013-04-13T18:37:14.177 回答