![]() |
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 PayPal data through the CData ADO.NET Provider, providing you with more flexibility and control.
Modify the App.config file in the project to add a reference to the PayPal Entity Framework 6 assembly and the connection string.
The provider surfaces tables from two PayPal APIs. The APIs use different authentication methods.
See the "Getting Started" chapter of the help documentation for a guide to obtaining the necessary API credentials.
To select the API you want to work with, you can set the Schema property to REST or SOAP. By default the SOAP schema will be used.
For testing purposes you can set UseSandbox to true and use sandbox credentials.
<configuration> ... <connectionStrings> <add name="PayPalContext" connectionString="Offline=False;Schema=SOAP;Username=sandbox-facilitator_api1.test.com;Password=xyz123;Signature=zx2127;InitiateOAuth=GETANDREFRESH;" providerName="System.Data.CData.PayPal" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.PayPal" type="System.Data.CData.PayPal.PayPalProviderServices, System.Data.CData.PayPal.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class PayPalContext : DbContext {
public PayPalContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<PayPalContext>(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("Transactions")]
public class Transactions {
[System.ComponentModel.DataAnnotations.Key]
public System.String Date { get; set; }
public System.String GrossAmount { get; set; }
}
public DbSet<Transactions> Transactions { set; get; }
PayPalContext context = new PayPalContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Transactions select line;
Download a free trial of the PayPal Data Provider to get started:
Download NowLearn more:
👁 PayPal IconEasy-to-use PayPal client enables .NET-based applications to easily consume PayPal Transactions, Orders, Sales, Invoices, etc.