Hi AymericKer, I hope you are doing good.
There are many where you can do it but the most common way is using SDK in C# language.
I use the following to create a connection to my enviorement and then to CRUD different entities.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Crm.Sdk.Messages;
using System.Net;
using System.ServiceModel;
using Microsoft.Xrm.Tooling.Connector;
using Microsoft.Xrm.Sdk.Query;
//THIS CODE IS USING SDK TO CONNECT TO DYNAMICS WITH C#
namespace DynamicsLinkToVS
{
class Program
{
static void Main(string[] args)
{
IOrganizationService oServiceProxy;
try
{
Console.WriteLine("Setting up Dynamics 365 connection");//This line create the Dynamics 365 Connection:
CrmServiceClient oMSCRMConn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient("AuthType=Office365;"
"Username=test.com;Password=test;URL=test.com");
//Now Create the IOrganizationService
oServiceProxy = (IOrganizationService)oMSCRMConn.OrganizationWebProxyClient != null ?
(IOrganizationService)oMSCRMConn.OrganizationWebProxyClient :
(IOrganizationService)oMSCRMConn.OrganizationServiceProxy;
Console.WriteLine("Validating Connection");
if (oServiceProxy != null)
{
//Get the current User Id
Guid userId = ((WhoAmIResponse)oServiceProxy.Execute(new WhoAmIRequest())).UserId;
if (userId != Guid.Empty)
{
Console.WriteLine("Connection Successful");
//Creating a new entity
var mycontact = new Entity("contact");
mycontact.Attributes["firstname"] = "test";
//Create a new contact and returns an Id because create function returns an Id
Guid recordId = oMSCRMConn.Create(mycontact);
//Create a new Entity as contact
Entity aux = new Entity("contact");
//Save the Id in the Id of aux
aux.Id = recordId;
//Update something
aux.Attributes["lastname"] = "test";
//Changes are applied to the enviorement
oMSCRMConn.Update(aux);
//Get record
Entity contact = oMSCRMConn.Retrieve("contact", recordId, new ColumnSet("firstname", "lastname"));
Console.WriteLine(contact.Attributes["lastname"]);
//Delete record created
oMSCRMConn.Delete("contact", recordId);
//Get all contacts
QueryExpression query = new QueryExpression("contact");
query.ColumnSet = new ColumnSet("firstname", "lastname");
EntityCollection ec = oMSCRMConn.RetrieveMultiple(query);
for (int i = 0; i < ec.Entities.Count; i )
{
if (ec.Entities[i].Attributes.ContainsKey("firstname"))
{
Console.WriteLine(ec.Entities[i].Attributes["firstname"]);
}
}
}
}
else
{
Console.WriteLine("Connection failed");
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " ex.ToString());
}
Console.ReadKey();
}
}
}
You can use that as a reference.
I this answers your question please check it as verified to help others finding useful information.
Here additional info that can be valuable:
QueryExpression Class (Microsoft.Xrm.Sdk.Query) | Microsoft Docs
Welcome to this amazing community.