![]() |
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 Adobe Target 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 Adobe Target Entity Framework 6 assembly and the connection string.
To connect to Adobe Target, you must provide the Tenant property along with OAuth connection properties mentioned below. Note that while other connection properties can influence processing behavior, they do not affect the ability to connect.
To determine your Tenant name:
You must set AuthScheme to OAuthClient for all user account flows.
Note: Adobe authentication via OAuth requires updating your token every two weeks.
Obtaining the OAuth Access Token
Set the following properties to connect:
With these settings, the provider obtains an access token from Adobe Target, which it uses to request data. The OAuth values are stored in the location specified by OAuthSettingsLocation, ensuring they persist across connections.
<configuration> ... <connectionStrings> <add name="AdobeTargetContext" connectionString="Offline=False;Tenant=mycompanyname;InitiateOAuth=GETANDREFRESH;" providerName="System.Data.CData.AdobeTarget" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.AdobeTarget" type="System.Data.CData.AdobeTarget.AdobeTargetProviderServices, System.Data.CData.AdobeTarget.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class AdobeTargetContext : DbContext {
public AdobeTargetContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<AdobeTargetContext>(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("Activities")]
public class Activities {
[System.ComponentModel.DataAnnotations.Key]
public System.String Id { get; set; }
public System.String Name { get; set; }
}
public DbSet<Activities> Activities { set; get; }
AdobeTargetContext context = new AdobeTargetContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Activities select line;
Download a free trial of the Adobe Target Data Provider to get started:
Download NowLearn more:
👁 Adobe Target IconEasily connect .NET applications with real-time data. Use Adobe Target to manage the data that powers your applications.