![]() |
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 Cvent 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 Cvent Entity Framework 6 assembly and the connection string.
Before you can authenticate to Cvent, you must create a workspace and an OAuth application.
To create a workspace:
| event/attendees:read | event/attendees:write | event/contacts:read |
| event/contacts:write | event/custom-fields:read | event/custom-fields:write |
| event/events:read | event/events:write | event/sessions:delete |
| event/sessions:read | event/sessions:write | event/speakers:delete |
| event/speakers:read | event/speakers:write | budget/budget-items:read |
| budget/budget-items:write | exhibitor/exhibitors:read | exhibitor/exhibitors:write |
| survey/surveys:read | survey/surveys:write |
After you have set up a Workspace and invited them, developers can sign up and create a custom OAuth app. See the Creating a Custom OAuth Application section in the Help documentation for more information.
After creating an OAuth application, set the following connection properties to connect to Cvent:
<configuration> ... <connectionStrings> <add name="CventContext" connectionString="Offline=False;OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;InitiateOAuth=GETANDREFRESH;" providerName="System.Data.CData.Cvent" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.Cvent" type="System.Data.CData.Cvent.CventProviderServices, System.Data.CData.Cvent.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class CventContext : DbContext {
public CventContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<CventContext>(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("Events")]
public class Events {
[System.ComponentModel.DataAnnotations.Key]
public System.String Id { get; set; }
public System.String Title { get; set; }
}
public DbSet<Events> Events { set; get; }
CventContext context = new CventContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Events select line;
Download a free trial of the Cvent Data Provider to get started:
Download NowLearn more:
👁 Cvent IconRapidly create and deploy powerful .NET applications that integrate with Cvent.