Codefix.Dataverse 2.0.0

dotnet add package Codefix.Dataverse --version 2.0.0
                    
NuGet\Install-Package Codefix.Dataverse -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Codefix.Dataverse" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Codefix.Dataverse" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Codefix.Dataverse" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Codefix.Dataverse --version 2.0.0
                    
#r "nuget: Codefix.Dataverse, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Codefix.Dataverse@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Codefix.Dataverse&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Codefix.Dataverse&version=2.0.0
                    
Install as a Cake Tool

Codefix.Dataverse

NuGet package for connecting to Microsoft Dataverse using an EF Core–style DbContext and DbSet pattern over the Dataverse Web API (OData).

Package Codefix.Dataverse
Target .NET 10 (net10.0)
Repository Varsium/Codefix.DataverseNuget

Features

  • ODataDbContext / ODataDbSet<T> for querying entities with LINQ-like filters, expand, select, order-by, paging
  • CRUD helpers: ToListAsync, FirstOrDefaultAsync, CreateAsync, UpdateAsync, DeleteAsync
  • Dependency injection via AddOdataDbContext and AddDataverse
  • Azure AD app registration, client secret, or TokenCredential (e.g. DefaultAzureCredential / managed identity)
  • Multi-environment factory via AddDataverseFactory and keyed IDataverseFactory
  • Attributes for table names, primary keys, lookups, and read-only fields

Installation

dotnet add package Codefix.Dataverse

Requires .NET 10 and a Dataverse environment URL (e.g. https://yourorg.crm4.dynamics.com).

Quick start

1. Define entities

Map each Dataverse table to a class and decorate it with [ODataTable("logical_name")]. Use [JsonProperty] (Newtonsoft) for column logical names.

using Codefix.Dataverse.Attributes;
using Newtonsoft.Json;

[ODataTable("account")]
public class Account
{
    [OdataPrimaryKey]
    [JsonProperty("accountid")]
    public Guid? AccountId { get; set; }

    [JsonProperty("name")]
    public string? Name { get; set; }
}

Optional: inherit DataverseRecord for standard audit columns (createdon, modifiedon, etc.).

2. Define a DbContext

using Codefix.Dataverse.Core;

public class CrmDb : ODataDbContext
{
    public ODataDbSet<Account> Accounts { get; set; } = null!;
}

3. Register in DI (ASP.NET Core)

Client secret

using Codefix.Dataverse.Bootstrappers;

builder.Services.AddOdataDbContext<CrmDb>(options =>
{
    options.BaseUrl = "https://yourorg.crm4.dynamics.com";
    options.TenantId = "<tenant-id>";
    options.ClientId = "<app-id>";
    options.ClientSecret = "<secret>";
});

Managed identity / Azure credential

using Azure.Identity;
using Codefix.Dataverse.Bootstrappers;

builder.Services.AddOdataDbContext<CrmDb>(options =>
{
    options.BaseUrl = "https://yourorg.crm4.dynamics.com";
    options.Credentials = new DefaultAzureCredential();
});

4. Query and mutate

public class AccountService(CrmDb db)
{
    public async Task<IList<Account>> GetActiveAccountsAsync() =>
        await db.Accounts
            .Where(a => a.Name != null)
            .Top(50)
            .ToListAsync();

    public async Task<Account?> GetByIdAsync(Guid id) =>
        await db.Accounts.FirstOrDefaultAsync(id);

    public async Task<Account> CreateAsync(Account account) =>
        await db.Accounts.CreateAsync(account);
}

Inject CrmDb (registered as transient per request scope in the sample above).

Low-level Web API access

Register only IDataverseService when you do not need ODataDbContext:

builder.Services.AddDataverse(options =>
{
    options.BaseUrl = "https://yourorg.crm4.dynamics.com";
    options.Credential = new DefaultAzureCredential();
    options.Lifetime = ServiceLifetime.Scoped;
});

Use GetEntityInDataverse, PostEntityInDataverse, PatchEntityInDataverse, PutEntityInDataverse, and DeleteEntityInDataverse on IDataverseService.

Multiple environments

builder.Services.AddDataverseFactory(options =>
{
    options.AddDataVerseConfig("Production", "https://prod.crm.dynamics.com", tenantId, clientId, secret);
    options.AddDataVerseConfig("Test", "https://test.crm.dynamics.com", tenantId, clientId, secret);
});

// Resolve by key
var prod = factory.CreateService("Production");

Attributes

Attribute Purpose
ODataTable Logical name of the Dataverse table
OdataPrimaryKey Primary key property for updates/deletes
ODataBind Lookup / navigation binding (@odata.bind)
ODataReadonly Skip property on create/update payloads

Sandbox

The Sandbox project in this repository is a minimal ASP.NET Core app demonstrating AddOdataDbContext and ToListAsync. Replace the sample environment URL and credentials before running.

dotnet run --project Sandbox

Publish to NuGet.org

  1. Create an API key at nuget.org (scope: Codefix.Dataverse).
  2. Pack and push from the repo root:
dotnet pack Codefix.Dataverse/Codefix.Dataverse.csproj -c Release
dotnet nuget push Codefix.Dataverse/bin/Release/Codefix.Dataverse.*.nupkg --api-key <YOUR_API_KEY> --source https://api.nuget.org/v3/index.json
  1. In consuming repos:
dotnet add package Codefix.Dataverse

Versioning

  • 1.x – .NET 6 / 8 (legacy, last NuGet: 1.2.6)
  • 2.0.0 – .NET 10 (current)

See GitHub releases for changelog details.

License

MIT – see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 44 6/4/2026
1.2.6 187 11/7/2024