![]() |
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 Data Cloud 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 Data Cloud Entity Framework 6 assembly and the connection string.
Salesforce Data Cloud supports authentication via the OAuth standard.
Set to OAuth.
CData provides an embedded OAuth application that simplifies authentication at the desktop.
You can also authenticate from the desktop via a custom OAuth application, which you configure and register at the Salesforce Data Cloud console. For further information, see Creating a Custom OAuth App in the Help documentation.
Before you connect, set these properties:
When you connect, the driver opens Salesforce Data Cloud's OAuth endpoint in your default browser. Log in and grant permissions to the application.
The driver then completes the OAuth process as follows:
For other OAuth methods, including Web Applications and Headless Machines, refer to the Help documentation.
<configuration> ... <connectionStrings> <add name="SalesforceDataCloudContext" connectionString="Offline=False;InitiateOAuth=GETANDREFRESH;" providerName="System.Data.CData.SalesforceDataCloud" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.SalesforceDataCloud" type="System.Data.CData.SalesforceDataCloud.SalesforceDataCloudProviderServices, System.Data.CData.SalesforceDataCloud.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class SalesforceDataCloudContext : DbContext {
public SalesforceDataCloudContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<SalesforceDataCloudContext>(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("Account")]
public class Account {
[System.ComponentModel.DataAnnotations.Key]
public System.String [Account ID] { get; set; }
public System.String [Account Name] { get; set; }
}
public DbSet<Account> Account { set; get; }
SalesforceDataCloudContext context = new SalesforceDataCloudContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Account select line;
Download a free trial of the Salesforce Data Cloud Data Provider to get started:
Download NowLearn more:
👁 Salesforce Data Cloud IconRapidly create and deploy powerful .NET applications that integrate with Salesforce Data Cloud.