![]() |
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 Salesloft 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 Salesloft Entity Framework 6 assembly and the connection string.
SalesLoft authenticates using the OAuth authentication standard or an API Key. OAuth requires the authenticating user to interact with SalesLoft using the browser.Alternatively, you can authenticate with an APIKey. Provision an API key from the SalesLoft user interface: https://accounts.salesloft.com/oauth/applications/. You will receive a Key which will be used when issuing requests.
<configuration> ... <connectionStrings> <add name="SalesLoftContext" connectionString="Offline=False;AuthScheme=OAuth;OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;CallbackUrl=http://localhost:33333;InitiateOAuth=GETANDREFRESH;" providerName="System.Data.CData.SalesLoft" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.SalesLoft" type="System.Data.CData.SalesLoft.SalesLoftProviderServices, System.Data.CData.SalesLoft.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class SalesLoftContext : DbContext {
public SalesLoftContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<SalesLoftContext>(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("Accounts")]
public class Accounts {
[System.ComponentModel.DataAnnotations.Key]
public System.String Id { get; set; }
public System.String Name { get; set; }
}
public DbSet<Accounts> Accounts { set; get; }
SalesLoftContext context = new SalesLoftContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Accounts select line;
Download a free trial of the Salesloft Data Provider to get started:
Download NowLearn more:
👁 Salesloft IconRapidly create and deploy powerful .NET applications that integrate with Salesloft.