![]() |
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 Salesforce Marketing 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 Salesforce Marketing Entity Framework 6 assembly and the connection string.
Authenticating to the Salesforce Marketing Cloud APIs
Set the and to your login credentials, or to the credentials for a sandbox user if you are connecting to a sandbox account.
Connecting to the Salesforce Marketing Cloud APIs
By default, the data provider connects to production environments. Set to true to use a Salesforce Marketing Cloud sandbox account.
The default Instance is s7 of the Web Services API; however, if you use a different instance, you can set .
<configuration> ... <connectionStrings> <add name="SFMarketingCloudContext" connectionString="Offline=False;User=myUser;Password=myPassword;InitiateOAuth=GETANDREFRESH;" providerName="System.Data.CData.SFMarketingCloud" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.SFMarketingCloud" type="System.Data.CData.SFMarketingCloud.SFMarketingCloudProviderServices, System.Data.CData.SFMarketingCloud.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class SFMarketingCloudContext : DbContext {
public SFMarketingCloudContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<SFMarketingCloudContext>(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("Subscriber")]
public class Subscriber {
[System.ComponentModel.DataAnnotations.Key]
public System.String Id { get; set; }
public System.String Status { get; set; }
}
public DbSet<Subscriber> Subscriber { set; get; }
SFMarketingCloudContext context = new SFMarketingCloudContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Subscriber select line;
Download a free trial of the Salesforce Marketing Data Provider to get started:
Download NowLearn more:
👁 Salesforce Marketing Cloud IconRapidly create and deploy powerful .NET applications that integrate with Salesforce Marketing Cloud data including Accounts, Emails, Lists, Subscribers, and more!