Codefix.Dataverse
2.0.0
dotnet add package Codefix.Dataverse --version 2.0.0
NuGet\Install-Package Codefix.Dataverse -Version 2.0.0
<PackageReference Include="Codefix.Dataverse" Version="2.0.0" />
<PackageVersion Include="Codefix.Dataverse" Version="2.0.0" />
<PackageReference Include="Codefix.Dataverse" />
paket add Codefix.Dataverse --version 2.0.0
#r "nuget: Codefix.Dataverse, 2.0.0"
#:package Codefix.Dataverse@2.0.0
#addin nuget:?package=Codefix.Dataverse&version=2.0.0
#tool nuget:?package=Codefix.Dataverse&version=2.0.0
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
AddOdataDbContextandAddDataverse - Azure AD app registration, client secret, or
TokenCredential(e.g.DefaultAzureCredential/ managed identity) - Multi-environment factory via
AddDataverseFactoryand keyedIDataverseFactory - 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
- Create an API key at nuget.org (scope:
Codefix.Dataverse). - 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
- 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 | Versions 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. |
-
net10.0
- Azure.Identity (>= 1.14.2)
- Azure.Security.KeyVault.Secrets (>= 4.8.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.PowerPlatform.Dataverse.Client (>= 1.2.10)
- Newtonsoft.Json (>= 13.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.