在FK字段中插入Null [英] Inserting a Null in an FK field
问题描述
Hi *,
我的发票ID为 PK Invoice表中的 和另一个表中的FK(Transactions),Transactions表中的invoice_id字段为Nullable。 我之间建立了0(或1)到多个关系表格。
I have an Invoice ID as the PK in the Invoice table and a FK in another table (Transactions) the invoice_id field in the Transactions table is Nullable. I have a 0 (or 1) to many relationship established between the tables.
我创建了事务记录(使用null invoice_id字段),然后可以更新invoice_id字段,没有任何问题。 但是,当取消发票时,我需要进入每个交易记录并将invoice_id字段设置为空。 这是我收到错误的地方
I create the Transaction record (with a null invoice_id field), then later can update the invoice_id field with no problems. However, when an Invoice is cancelled I need to go into each of the transaction records and set the invoice_id field back to null. This is where I am getting the error
"值不能为空。参数名称:keyValue"
I我正在使用以下代码
foreach (交易 tm in _ListTrans)
foreach (Transactions tm in _ListTrans)
{
tm.Invoic esReference.EntityKey =
new EntityKey (" myEntities.Invoices" ," invoice_id" , null );
new EntityKey("myEntities.Invoices", "invoice_id", null);
}
我该怎么做?
感谢您的帮助!
Eric
推荐答案
只需输入此代码
just put this code
foreach (Transactions tm in _ListTrans)
{
tm.Invoices = null;
}
这篇关于在FK字段中插入Null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!