![]() |
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 Zendesk 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 Zendesk Entity Framework 6 assembly and the connection string.
To connect, set the URL and provide authentication. The URL is your Zendesk Support URL: https://{subdomain}.zendesk.com.
You can authenticate using the Basic or OAuth methods.
To use Basic authentication, specify your email address and password or your email address and an API token. Set User to your email address and follow the steps below to provide the Password or ApiToken.
See the Getting Started guide in the CData driver documentation for an authentication guide.
<configuration> ... <connectionStrings> <add name="ZendeskContext" connectionString="Offline=False;URL=https://subdomain.zendesk.com;[email protected];Password=test123;InitiateOAuth=GETANDREFRESH;" providerName="System.Data.CData.Zendesk" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.Zendesk" type="System.Data.CData.Zendesk.ZendeskProviderServices, System.Data.CData.Zendesk.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class ZendeskContext : DbContext {
public ZendeskContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<ZendeskContext>(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("Tickets")]
public class Tickets {
[System.ComponentModel.DataAnnotations.Key]
public System.String Id { get; set; }
public System.String Subject { get; set; }
}
public DbSet<Tickets> Tickets { set; get; }
ZendeskContext context = new ZendeskContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Tickets select line;
Download a free trial of the Zendesk Data Provider to get started:
Download NowLearn more:
👁 Zendesk IconRapidly create and deploy powerful .NET applications that integrate with Zendesk data including Tickets, Groups, Users, Schedules, and more!