在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接受此数量的参数”
有什么想法吗?
答案 0 :(得分:2)
deleteModuleChanges
是IEnumerable
,所以当你向它添加()
时,VB.NET编译器会尝试在该集合上触发ElementAtOrDefault
扩展方法,这是不可能完成的没有参数。试试那个:
For Each amendment As Amendments_Awaiting_Approval In deleteModuleChanges
db.OrderDetails.DeleteOnSubmit(detail)
Next
但是,我不知道你为什么要迭代amendment
,而是删除detail
。你确定那是你想做的吗?
当然,您必须提交更改:
db.SubmitChanges()