![]() |
VOOZH | about |
Microsoft Entity Framework serves as an object-relational mapping framework for working with data represented as objects. Although Visual Studio offers the ADO.NET Entity Data Model wizard to automatically generate the Entity Model, this model-first approach may present challenges when your data source undergoes changes or when you require greater control over entity operations. In this article, we will delve into the code-first approach for accessing Xero data through the CData ADO.NET Provider, providing you with more flexibility and control.
Accessing and integrating live data from Xero has never been easier with CData. Customers rely on CData connectivity to:
Customers regularly integrate their Xero data with preferred tools, like Tableau, Qlik Sense, or Excel, and integrate Xero data into their database or data warehouse.
Modify the App.config file in the project to add a reference to the Xero Entity Framework 6 assembly and the connection string.
To connect, set the Schema connection property in addition to any authentication values. Xero offers authentication for private applications, public applications, and partner applications. Set the XeroAppAuthentication property to PUBLIC, PRIVATE, or PARTNER, depending on the type of application configured. To connect from a private application, you will additionally need to set the OAuthAccessToken, OAuthClientId, OAuthClientSecret, CertificateStoreType, CertificateStore, and CertificateStorePassword.
To connect from a public or partner application, you can use the embedded OAuthClientId, OAuthClientSecret, and CallbackURL, or you can register an app to obtain your own OAuth values.
See the "Getting Started" chapter of the help documentation for a guide to authenticating to Xero.
<configuration> ... <connectionStrings> <add name="XeroContext" connectionString="Offline=False;InitiateOAuth=GETANDREFRESH;" providerName="System.Data.CData.Xero" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.Xero" type="System.Data.CData.Xero.XeroProviderServices, System.Data.CData.Xero.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class XeroContext : DbContext {
public XeroContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<XeroContext>(null);
// To remove the plural names
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;
[System.ComponentModel.DataAnnotations.Schema.Table("Items")]
public class Items {
[System.ComponentModel.DataAnnotations.Key]
public System.String Name { get; set; }
public System.String QuantityOnHand { get; set; }
}
public DbSet<Items> Items { set; get; }
XeroContext context = new XeroContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Items select line;
Download a free trial of the Xero Data Provider to get started:
Download NowLearn more:
👁 Xero IconComplete read-write access to Xero accounting enables developers to search (Customers, Transactions, Invoices, Sales Receipts, etc.), update items, edit customers, and more, from any .NET application.