LINQ to QuickBooks

This article demonstrates how to use LINQ to access tables in QuickBooks through the QuickBooks ADO.NET Data Provider. To do this you will LINQ to Entity Framework, which is used to generate the connection and can be used with any CData ADO.NET Data Providers to access data via LINQ.

  1. In a new project in Visual Studio, right-click on the project and choose to add a new item. Add an ADO.NET Entity Data Model.
  2. Choose to generate from database and click next.
  3. Add a new Data Connection, and change your data source type to "CData QuickBooks Data Source".
  4. Enter your data source connection information.
  5. If saving your entity connection to App.Config, set an entity name. In this example we are setting QuickBooksEntities as our entity connection in App.Config.
  6. Enter a model name and select any tables or views you would like to include in the model.

Using the entity you created, you can now perform select, update, delete, and insert commands. For example:

QuickBooksEntities qbeContext = new QuickBooksEntities();

var invoiceQuery = from invoice in qbeContext.Invoices
  orderby invoice.CustomerName
  select invoice;

foreach (var result in invoiceQuery) {
  Console.WriteLine("{0} {1} ", result.Id, result.CustomerName);

See "LINQ and Entity Framework" chapter in the help documentation for example queries of the supported LINQ.