ADO.NET Provider for Azure DevOps

Build 25.0.9434

Code-First Approach

An alternative to generating classes automatically from the provider is to handwrite your model classes. This is the code-first approach to Entity Framework, which gives you greater control over the exact data model you use in your application.

Create the Context Class

Start by creating a context class that inherits from DbContext. This class should expose DbSet properties that represent the tables you want to access. Use the OnConfiguring method to initialize the connection.

using Microsoft.EntityFrameworkCore;

public class AzureDevOpsContext : DbContext
{
	public DbSet<MyTable> MyTable { get; set; }

	protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
	{
		if (!optionsBuilder.IsConfigured)
		{
			optionsBuilder.UseAzureDevOps("AuthScheme=Basic;Organization=MyAzureDevOpsOrganization;Catalog=Project_dev;Schema=Project;PersonalAccessToken=MyPAT;");
		}
	}
}

Create the Table Models

Define a class for each table that was defined in the DbSet properties of the context class. The table classes should have a list of properties that correspond to each field of that table. A corresponding map class must be defined to configure attributes for each property in the table class.

public class MyTable
{
	public string KeyColumn { get; set; }
	public string MyColumn { get; set; }
}

Retrieving Records

You can retrieve records from a table as follows:

class Program
	{
		static void Main(string[] args)
		{
			AzureDevOpsContext context = new AzureDevOpsContext();
			var Query = from Lead in context.Lead;
			select Lead;
			foreach (var result in Query)
			{
				Console.WriteLine("{0}", result.KeyColumn);
				Console.WriteLine("{0}", result.MyColumn);
			}
			try
			{
				context.SaveChanges();
			}
			catch (Exception e)
			{
				Console.WriteLine(e);
			}
			Console.ReadLine();
		}
	}

Inserting Records

You can insert records into existing tables as follows:

class Program
	{
		static void Main(string[] args)
		{
			AzureDevOpsContext context = new AzureDevOpsContext();
			MyTable newRecord = new MyTable()
			{
				MyColumn1 = "Value1", MyColumn2 = "Value2"
			};
			context.WorkItems.Add(newRecord);
			try
			{
				context.SaveChanges();
				Console.WriteLine(newRecord.Id);
			}
			catch (Exception e)
			{
				Console.WriteLine(e);
			}
			Console.ReadLine();
		}
	}

Copyright (c) 2025 CData Software, Inc. - All rights reserved.
Build 25.0.9434