TimHanewich.Cds 0.8.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TimHanewich.Cds --version 0.8.0                
NuGet\Install-Package TimHanewich.Cds -Version 0.8.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="TimHanewich.Cds" Version="0.8.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TimHanewich.Cds --version 0.8.0                
#r "nuget: TimHanewich.Cds, 0.8.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.
// Install TimHanewich.Cds as a Cake Addin
#addin nuget:?package=TimHanewich.Cds&version=0.8.0

// Install TimHanewich.Cds as a Cake Tool
#tool nuget:?package=TimHanewich.Cds&version=0.8.0                

TimHanewich.Cds

A lightweight library for interacting with Microsoft's Dataverse service (formerly Common Data Service or "XRM"), the native data service of Microsoft's Power Platform and Dynamics 365 platform.

This library alleviates the need to create custom HTTP requests to interact with Dataverse. After providing the service with a few parameters, you can easily interact with the CDS through the traditional CRUD operators.

Install the package

To install the package in your .NET (C# or VB.NET) project, add the following package from NuGet: TimHanewich.Cds Run this command in the .NET CLI:

dotnet add package TimHanewich.Cds

Authenticating with Dataverse

This class library supports authentication to the Dataverse web API. Use the CdsAuthenticator class to authenticate.

CdsAuthenticator auth = new CdsAuthenticator();
auth.Username = "<your username>";
auth.Password = "<your password>";
auth.ClientId = Guid.Parse("51f81489-12ee-4a9e-aaae-a2591f45987d");
auth.Resource = "https://<your org>.crm.dynamics.com/";
await auth.GetAccessTokenAsync();

After running the GetAccessTokenAsync method, your access token will be stored inside the CdsAuthenticator object as the AccessToken property. Provide this AccessToken to the CdsService constructor (see below) to start using the Dataverse web API.

Initializing the CDS Service

Place the following import statements at the top of your code file.

using TimHanewich.Cds;  
using Newtonsoft.Json;  
using Newtonsoft.Json.Linq;

Create a new CDS Service

CdsService cds = new CdsService("YourOrgName", "YourAccessToken");

In the above example, replace "YourOrgName" with the organization name for your environment. For example, if your environment URL is https://org109a2adc0.crm.dynamics.com/, your org name is "org109a2adc0".

Replace "YourAccessToken" with the access token that you have received after authenticating through either the OAuth authentication flow or the above authentication using the CdsAuthenticator class (recommended).

Creating a record

We will use the CreateRecordAsync method of the CdsService to create a new record. This method accepts two parameters:
setter - the setter (schema) name of the entity. This can be found by going to https://<your_org_name>.crm.dynamics.com/api/data/v9.0/ in an authenticated window.
object_json - The JSON content of the record that you are creating.

A complete example of initializing a CDS Service and creating a new account record:

CdsService cds = new CdsService("YourOrgName", "YourAccessToken");
await cds.CreateRecordAsync("accounts", "{\"name\":\"123 Industries\"}");

Reading, Updating, and Deleting

The reading, updating, and deleting methods are very similar to the CreateRecordAsync method that is detailed above. The only difference is that these three methods also have a parameter called id which serves as the unique identifier of the record that you are trying to transact on.
This id parameter is the GUID value associated with the record that you can find in Dynamics 365 or the Power Platform CDS portal.

Working with Tables & Attributes

This package also provides the ability to read table and attribute structures. To leverage this capability import the resources by placing this statement at the top of your file:

using TimHanewich.Cds.Metadata;

Get a list of all records in the databse

Use the GetEntityMetadataSummariesAsync method to receive and array of record summaries:

EntityMetadataSummary[] summaries = await service.GetEntityMetadataSummariesAsync();

Each EntityMetadataSummary object contains the name of the record and "URL Extension" of the record that can be used to query records of this entity type.

Get metadata for a particular table

Use the GetEntityMetadataAsync method to access metadata for a particular table.

EntityMetadata AccountsTableData = service.GetEntityMetadataAsync("account").Result;

The EntityMetadata object provides details about all attributes (columns) in the table:

foreach (AttributeMetadata attribute in AccountsTableData.Attributes)
{
    Console.WriteLine(attribute.DisplayName);
    Console.WriteLine(attribute.SchemaName);
    Console.WriteLine(attribute.LogicalName);
    Console.WriteLine(attribute.Description);
    Console.WriteLine(attribute.AttributeType.ToString());
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.5.0 265 3/23/2023 2.5.0 is deprecated because it is no longer maintained.
2.4.1 213 3/21/2023
2.4.0 249 3/21/2023
2.3.0 218 3/21/2023
2.2.0 220 3/20/2023
2.1.0 218 3/20/2023
2.0.0 439 3/18/2022
1.0.0 411 3/15/2022
0.10.0 323 9/16/2021
0.9.0 364 5/6/2021
0.8.0 311 4/29/2021
0.7.0 299 4/29/2021
0.6.0 297 4/28/2021
0.5.0 326 4/24/2021
0.4.0 324 4/22/2021
0.3.1 330 4/20/2021
0.3.0 329 4/9/2021
0.2.1 459 9/18/2020
0.2.0 447 9/18/2020
0.1.0 426 9/14/2020