![]() |
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 Confluence 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 Confluence Entity Framework 6 assembly and the connection string.
An API token is necessary for account authentication. To generate one, login to your Atlassian account and navigate to API tokens > Create API token. The generated token will be displayed.
To connect to a Cloud account, provide the following (Note: Password has been deprecated for connecting to a Cloud Account and is now used only to connect to a Server Instance.):
To connect to a Server instance, provide the following:
<configuration> ... <connectionStrings> <add name="ConfluenceContext" connectionString="Offline=False;User=admin;APIToken=myApiToken;Url=https://yoursitename.atlassian.net;Timezone=America/New_York;" providerName="System.Data.CData.Confluence" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.Confluence" type="System.Data.CData.Confluence.ConfluenceProviderServices, System.Data.CData.Confluence.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class ConfluenceContext : DbContext {
public ConfluenceContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<ConfluenceContext>(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("Pages")]
public class Pages {
[System.ComponentModel.DataAnnotations.Key]
public System.String Key { get; set; }
public System.String Name { get; set; }
}
public DbSet<Pages> Pages { set; get; }
ConfluenceContext context = new ConfluenceContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Pages select line;
Download a free trial of the Confluence Data Provider to get started:
Download NowLearn more:
👁 Confluence IconRapidly create and deploy powerful .NET applications that integrate with Confluence.