我想使用 Umbraco Forms 不仅可以插入数据,还可以对其进行编辑。到目前为止,当我想编辑一条记录时,我通过查询字符串传入表单 guid 和记录 id,并在字段中填充正确的数据。到目前为止,一切都很好。
然后我像这样成功地连接到 Umbraco.Forms.Data.Storage.RecordStorage.RecordInserting 事件
void RecordStorage_RecordInserting(object sender, Umbraco.Forms.Core.RecordEventArgs e)
{
var ms = (Umbraco.Forms.Data.Storage.RecordStorage)sender;
if(this record exists){
ms.UpdateRecord(e.Record, e.Form);
}
}
但是,当我尝试提交已编辑的记录并运行 ms.RecordUpdate(e.Record, e.Form) 行时,我收到此错误
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_UFRecordDataString_UFRecordFields_Key". The conflict occurred in database "UmbracoPlay", table "dbo.UFRecordFields", column 'Key'.
The statement has been terminated.
我无法删除旧记录然后插入新记录,因为每次调用 ms.InsertRecord 时它都会重新引发相同的事件
我错过了什么?如何使用 Umbraco Forms 编辑现有数据?