![]() |
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 Bitbucket 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 Bitbucket Entity Framework 6 assembly and the connection string.
For most queries, you must set the Workspace. The only exception to this is the Workspaces table, which does not require this property to be set, as querying it provides a list of workspace slugs that can be used to set Workspace. To query this table, you must set Schema to 'Information' and execute the query SELECT * FROM Workspaces>.
Setting Schema to 'Information' displays general information. To connect to Bitbucket, set these parameters:
Bitbucket supports OAuth authentication only. To enable this authentication from all OAuth flows, you must create a custom OAuth application, and set AuthScheme to OAuth.
Be sure to review the Help documentation for the required connection properties for you specific authentication needs (desktop applications, web applications, and headless machines).
From your Bitbucket account:
<configuration> ... <connectionStrings> <add name="BitbucketContext" connectionString="Offline=False;Workspace=myworkspaceslug;Schema=Information;InitiateOAuth=GETANDREFRESH;" providerName="System.Data.CData.Bitbucket" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.Bitbucket" type="System.Data.CData.Bitbucket.BitbucketProviderServices, System.Data.CData.Bitbucket.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class BitbucketContext : DbContext {
public BitbucketContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// To remove the requests to the Migration History table
Database.SetInitializer<BitbucketContext>(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("Issues")]
public class Issues {
[System.ComponentModel.DataAnnotations.Key]
public System.String Title { get; set; }
public System.String ContentRaw { get; set; }
}
public DbSet<Issues> Issues { set; get; }
BitbucketContext context = new BitbucketContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Issues select line;
Download a free trial of the Bitbucket Data Provider to get started:
Download NowLearn more:
👁 Bitbucket IconRapidly create and deploy powerful .NET applications that integrate with Bitbucket.