这是我的数据库:
我想要实现的目标是:
我在 CustomerNote 中创建了 IssueLogId 外键(null)。你可以看到的连接是0..1到N,因此foreignKey可以是NULL。
数据按预期插入到CustomerIssue和IssueLog 中,但会引发错误:
找到导航链接'CustomerNotes',类型为'feed',但其匹配的导航属性属于EntityReference类型。类型为“feed”的导航链接必须与EntitySetReference类型的导航属性匹配。
第二个SaveChanges()发生错误:
public void AddNewCustomerIssue(HelpdeskCreateIssueModel model, int userId)
{
if (model.CustomerIssue != null)
{
model.CustomerIssue.CustomerId = userId;
model.CustomerIssue.CreatedByCustomer = userId;
model.CustomerIssue.ModifiedByCustomer = userId;
model.CustomerIssue.Status = 1;
model.CustomerIssue.IsDeleted = false;
model.CustomerIssue.IsPaused = false;
this.ClientRepositories.ProxyDB.AddToCustomerIssues(model.CustomerIssue);
this.ClientRepositories.ProxyDB.SaveChanges();
// issue log
model.IssueLog.CustomerIssueId = model.CustomerIssue.Id;
model.IssueLog.CreatedByCustomer = userId;
model.IssueLog.ModifiedByCustomer = userId;
this.ClientRepositories.ProxyDB.AddToIssueLogs(model.IssueLog);
this.ClientRepositories.ProxyDB.SaveChanges();
}
}