![]() |
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 PingOne 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 PingOne Entity Framework 6 assembly and the connection string.
To connect to PingOne, configure these properties:
is the ID of the PingOne environment in which your Worker application resides. This parameter is used only when the environment is using the default PingOne domain (auth.pingone). It is configured after you have created the custom OAuth application you will use to authenticate to PingOne, as described in Creating a Custom OAuth Application in the Help documentation.
First, find the value for this property:
WorkerAppEnvironmentId='11e96fc7-aa4d-4a60-8196-9acf91424eca'
Now set to the value of the Environment ID field.
is the base URL of the PingOne authorization server for the environment where your application is located. This property is only used when you have set up a custom domain for the environment, as described in the PingOne platform API documentation. See Custom Domains.
PingOne supports both OAuth and OAuthClient authentication. In addition to performing the configuration steps described above, there are two more steps to complete to support OAuth or OAuthCliet authentication:
Set to OAuth.
Get and Refresh the OAuth Access Token
After setting the following, you are ready to connect:
When you connect, the driver opens PingOne's OAuth endpoint in your default browser. Log in and grant permissions to the application. The driver then completes the OAuth process:
The driver refreshes the access token automatically when it expires.
For other OAuth methods, including Web Applications, Headless Machines, or Client Credentials Grant, refer to the Help documentation.
<configuration> ... <connectionStrings> <add name="PingOneContext" connectionString="Offline=False;AuthScheme=OAuth;WorkerAppEnvironmentId=eebc33a8-xxxx-4f3a-yyyy-d3e5262fd49e;Region=NA;OAuthClientId=client_id;OAuthClientSecret=client_secret;InitiateOAuth=GETANDREFRESH;" providerName="System.Data.CData.PingOne" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.PingOne" type="System.Data.CData.PingOne.PingOneProviderServices, System.Data.CData.PingOne.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class PingOneContext : DbContext {
public PingOneContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<PingOneContext>(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("[CData].[Administrators].Users")]
public class [CData].[Administrators].Users {
[System.ComponentModel.DataAnnotations.Key]
public System.String Id { get; set; }
public System.String Username { get; set; }
}
public DbSet<[CData].[Administrators].Users> [CData].[Administrators].Users { set; get; }
PingOneContext context = new PingOneContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.[CData].[Administrators].Users select line;
Download a free trial of the PingOne Data Provider to get started:
Download NowLearn more:
👁 PingOne IconRapidly create and deploy powerful .NET applications that integrate with PingOne.