本文介绍了ReferentialConstraint 中的依赖属性映射到存储生成的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
写入数据库时出现此错误:
I get this error when writing to the database:
ReferentialConstraint 中的依赖属性映射到存储生成的列.列:'PaymentId'.
public bool PayForItem(int terminalId, double paymentAmount,
eNums.MasterCategoryEnum mastercategoryEnum, int CategoryId, int CategoryItemId)
{
using (var dbEntities = new DatabaseAccess.Schema.EntityModel())
{
int pinnumber = 0;
long pinid = 1; //getPinId(terminalId,ref pinnumber) ;
var payment = new DatabaseAccess.Schema.Payment();
payment.CategoryId = CategoryId;
payment.ItemCategoryId = CategoryItemId;
payment.PaymentAmount = (decimal)paymentAmount;
payment.TerminalId = terminalId;
payment.PinId = pinid;
payment.HSBCResponseCode = "";
payment.DateActivated = DateTime.Now;
payment.PaymentString = "Payment";
payment.PromotionalOfferId = 1;
payment.PaymentStatusId = (int)eNums.PaymentStatus.Paid;
//payment.PaymentId = 1;
dbEntities.AddToPayments(payment);
dbEntities.SaveChanges();
}
return true;
}
架构是:
推荐答案
您是否可能在表之间定义了错误的列关系?
Is it possible that you defined a bad column relation between your tables?
就我而言,我有不同的列,其中一个设置为自动数字.
In my case, I had different columns and one was set as autonumeric.
这篇关于ReferentialConstraint 中的依赖属性映射到存储生成的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!