I'm using C# in Visual Studio 2015, targeting .Net Framework 4.6, using EF 6.1.3, and dotConnect for QuickBooks 1.6.378.
I get the following error:
The error occurs on the QBOEntities.SaveChanges() line, in the following code. Also QBOEntities is defined as "public partial class QuickBooksEntities : ObjectContext".Exception thrown: 'System.Data.Entity.Core.UpdateException' in EntityFramework.dll
A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'JournalEntryId'.
Code: Select all
vJournalEntry = QBOEntities.JournalEntries.CreateObject();
QBOEntities.JournalEntries.AddObject(vJournalEntry);
vJournalEntry.TxnDate = vInvoice.INVOICEDATE;
vJournalEntry.DocNumber = $"FI{vInvoice.INVOICE_NO}";
vJournalEntry.PrivateNote = vInvoiceMemo;
if (!string.IsNullOrWhiteSpace(vInvoice.TAXE1_SHORTDESC))
{
vTaxCodeID = GetTaxForShortDesc(vInvoice.TAXE1_SHORTDESC)?.QBO_ACCOUNTING_ID;
}
else
{
vTaxCodeID = string.Empty;
}
vClassID = vInvoice.OfficeDepartment?.QBO_ACCOUNT_ID;
if (string.IsNullOrWhiteSpace(vClassID))
{
vClassID = vInvoice.OfficeMaster?.QBO_ACCOUNT_ID;
}
#region Invoice Header
vJournalEntryLineItem = QBOEntities.JournalEntryLineItems.CreateObject();
//QBOEntities.JournalEntryLineItems.AddObject(vJournalEntryLineItem);
vJournalEntryLineItem.Amount = Math.Abs(vInvoice.PATIENT_SUBTOTAL.GetValueOrDefault(0));
if (!string.IsNullOrWhiteSpace(vTaxCodeID))
{
vJournalEntryLineItem.JournalEntryLineDetailTaxCodeRefId = vTaxCodeID;
vJournalEntryLineItem.JournalEntryLineDetailTaxApplicableOn = FiloptoQBOConstants.QBOSales;
vJournalEntryLineItem.JournalEntryLineDetailTaxAmount = Math.Abs(vInvoice.TAXE1_AMOUNT.GetValueOrDefault(0)) + Math.Abs(vInvoice.TAXE2_AMOUNT.GetValueOrDefault(0)) + Math.Abs(vInvoice.TAXE3_AMOUNT.GetValueOrDefault(0));
}
if (vInvoice.PATIENT_SUBTOTAL.GetValueOrDefault(0) > 0)
{
vJournalEntryLineItem.JournalEntryLineDetailPostingType = FiloptoQBOConstants.QBODebit;
}
else
{
vJournalEntryLineItem.JournalEntryLineDetailPostingType = FiloptoQBOConstants.QBOCredit;
}
vJournalEntryLineItem.JournalEntryLineDetailAccountRefId = QBOSettings.QBOnlineSettings.AR_ACCOUNT_ID;
vJournalEntryLineItem.Description = vInvoiceMemo;
vJournalEntryLineItem.JournalEntryLineDetailClassRefId = vClassID;
vJournalEntry.JournalEntryLineItems.Add(vJournalEntryLineItem);
#endregion
#region Invoice Lines
foreach (INVOICEDETAIL vInvoiceLineItem in vInvoice.InvoiceDetails)
{
vJournalEntryLineItem = QBOEntities.JournalEntryLineItems.CreateObject();
//QBOEntities.JournalEntryLineItems.AddObject(vJournalEntryLineItem);
vJournalEntryLineItem.Amount = Math.Abs(vInvoiceLineItem.PATIENT_SUBTOTAL.GetValueOrDefault(0));
if (!string.IsNullOrWhiteSpace(vTaxCodeID))
{
vJournalEntryLineItem.JournalEntryLineDetailTaxCodeRefId = vTaxCodeID;
vJournalEntryLineItem.JournalEntryLineDetailTaxApplicableOn = FiloptoQBOConstants.QBOSales;
vJournalEntryLineItem.JournalEntryLineDetailTaxAmount = Math.Abs(vInvoiceLineItem.TAXE_1_AMOUNT.GetValueOrDefault(0)) + Math.Abs(vInvoiceLineItem.TAXE_2_AMOUNT.GetValueOrDefault(0)) + Math.Abs(vInvoiceLineItem.TAXE_3_AMOUNT.GetValueOrDefault(0));
}
if (vInvoiceLineItem.PATIENT_SUBTOTAL.GetValueOrDefault(0) > 0)
{
vJournalEntryLineItem.JournalEntryLineDetailPostingType = FiloptoQBOConstants.QBOCredit;
}
else
{
vJournalEntryLineItem.JournalEntryLineDetailPostingType = FiloptoQBOConstants.QBODebit;
}
vJournalEntryLineItem.JournalEntryLineDetailAccountRefId = GetItemTypeFeesAccountID(vInvoiceLineItem.ITEMTYPE);
vJournalEntryLineItem.Description = $"{vInvoiceMemo}, Line Item: {vInvoiceLineItem.STATEMENT}";
vJournalEntry.JournalEntryLineItems.Add(vJournalEntryLineItem);
}
#endregion
QBOEntities.SaveChanges();