【发布时间】: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