【问题标题】:Trying to create a Quickbooks Online Journal Entry using Devart dotConnect for Quickbooks尝试使用 Devart dotConnect for Quickbooks 创建 Quickbooks 在线日记条目
【发布时间】:2020-08-20 17:23:37
【问题描述】:

我正在使用 Devart 的 dotConnect for Quickbooks 实用程序使用 C# 和实体框架在 Quickbooks Online 中创建一些常规日记条目。 (dotConnect for Quickbooks 是 1.10 版,Entity Framework 是 6 版)

我在 Devart 的论坛上发现了一篇文章:forum link 这表明这不是您在公园里散步的正常实体框架。

支持向 OP 建议将条目组装为 Json 并将其分配给 JournalEntry.Line 属性。

当我这样做时,它会抛出一个错误: “无法将类型为 'Newtonsoft.Json.Linq.g' 的对象转换为类型 'Newtonsoft.Json.Linq.o'”

当点击 ...SaveChanges() 方法时。向谷歌查询该错误没有任何结果。有没有人遇到过这种情况?

到目前为止我已经尝试过:

  • 使用对象数组而不是对象列表
  • 使用 Microsoft 的 Json 序列化程序

谢谢!

代码如下: '''

            QuickbooksEntities contextQuickbooks = new QuickbooksEntities();
            JournalEntry je = new JournalEntry();

            //Query to the the QBO Account objects for our known AcctNum values
            Account creditAccount = contextQuickbooks.Accounts.Where(x => x.AcctNum == "4060-1").FirstOrDefault();
            Account debitAccount = contextQuickbooks.Accounts.Where(x => x.AcctNum == "1111").FirstOrDefault();

            // Build the credit and debit objects
            JournalEntryLineItem creditLine = new JournalEntryLineItem();
            creditLine.LineId = "0";
            creditLine.JournalEntryLineDetail_AccountRefId = creditAccount.Id;
            creditLine.JournalEntryLineDetail_AccountRefName = creditAccount.Name;
            creditLine.JournalEntryLineDetail_PostingType = "Credit";
            creditLine.DetailType = "JournalEntryLineDetail";
            creditLine.Amount = (decimal)3;
            
            JournalEntryLineItem debitLine = new JournalEntryLineItem();
            debitLine.LineId = "1";
            debitLine.JournalEntryLineDetail_AccountRefId = debitAccount.Id;
            debitLine.JournalEntryLineDetail_AccountRefName = debitAccount.Name;
            debitLine.JournalEntryLineDetail_PostingType = "Debit";
            debitLine.DetailType = "JournalEntryLineDetail";
            debitLine.Amount = (decimal)3;


            // Add the line items to a list
            List<JournalEntryLineItem> lines = new List<JournalEntryLineItem>();
            lines.Add(creditLine);
            lines.Add(debitLine);
            // Convert the list of line item objects to json
            var json = Newtonsoft.Json.JsonConvert.SerializeObject(lines);

            //JournalEntry journalEntry = new JournalEntry();
            je.TxnDate = DateTime.Now.Date;
            je.CurrencyRefId = "USD";

            // Pass the json string to the JournalEntry.Line property
            je.Line = json;
            
            // The Entity Framework magic
            contextQuickbooks.JournalEntries.Add(je);
            contextQuickbooks.SaveChanges();

'''

【问题讨论】:

    标签: json entity-framework quickbooks devart


    【解决方案1】:

    在 JournalEntryLineItem 对象中序列化 LinkedTxn 字段的空值的错误已在 dotConnect for QuickBooks v1.10.1351 中得到修复。

    在 v1.10.1375 中,EF Core(通过 EF Core 模板)和 EF6(通过 DbContext 模板)支持 JSON(Newtonsoft.Json、Microsoft.Text.Json)和 YAML (YamlDotNet) 序列化。

    请参阅https://www.devart.com/dotconnect/quickbooks/revision_history.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-12
      • 1970-01-01
      相关资源
      最近更新 更多