I am not using Cloud service of Dynamic CRM 2015, we are using On Premise version of Dynamic CRM 2015.
I have done a PoC on performance comparision between FetchXML and Devart ADO.NET Provider for Dynamics CRM with Entity Framework, where in I have found that FetchXML is performing better as compared to devart driver.
Time Taken by FetchXML: - 39445(milisec) for 42 rows
Time Taken by Devart : - 49279(milisec) for 42 rows
Find below code for both approach's and suggest if there is anything which can be done to perform better.
---------------------------------------DevArt ADO.NEt Provider for Dynamic CRM with Entity Framework--------
Code: Select all
class Program
{
static void Main(string[] args)
{
var watch = System.Diagnostics.Stopwatch.StartNew();
Entities context = new Entities();
var query = from cnt in context.contact
orderby cnt.firstname, cnt.lastname
select cnt;
int i = 0;
foreach (contact con in query)
{
i++;
Console.WriteLine("{0} | {1} | {2}", con.contactid, con.firstname, con.lastname);
}
watch.Stop();
Console.WriteLine("Record Count: " + i.ToString());
Console.WriteLine("Time Taken: " + watch.ElapsedMilliseconds.ToString());
Console.ReadLine();
}
}
---------------------------------------FetchXML Query--------
We have used below helper files / classes provided by Microsoft.
CRMServices\crmservicehelpers.cs
CRMServices\deviceidmanager.cs
CRMServices\myorganizationcrmsdktypes.cs
Code: Select all
class Program
{
static void Main(string[] args)
{
FetchData(Singleton.Service);
Console.ReadLine();
}
static void FetchData(IOrganizationService _Service)
{
var watch = System.Diagnostics.Stopwatch.StartNew();
string contactQuery = @"<fetch mapping='logical' version='1.0'>
<entity name='contact'>
<attribute name='contactid' />
<attribute name='firstname' />
<attribute name='lastname' />
</entity></fetch>";
EntityCollection associatedContacts_result = _Service.RetrieveMultiple(new FetchExpression(contactQuery));
int i = 0;
foreach (var c in associatedContacts_result.Entities)
{
i++;
string contactId = string.Empty, firstName = string.Empty, lastName = string.Empty;
if (!string.IsNullOrEmpty(((Guid)c.Attributes["contactid"]).ToString()))
contactId = ((Guid)c.Attributes["contactid"]).ToString();
if (!string.IsNullOrEmpty((string)c.Attributes["firstname"]))
firstName = ((string)c.Attributes["firstname"]);
if(!string.IsNullOrEmpty(((Contact)c).FirstName.ToString()))
lastName = ((Contact)c).FirstName.ToString();
Console.WriteLine("{0} | {1} | {2}", contactId, firstName, lastName);
}
watch.Stop();
Console.WriteLine("Record Count=" +i.ToString());
Console.WriteLine("Time Taken: " + watch.ElapsedMilliseconds.ToString());
}
}
public class Singleton
{
private static IOrganizationService _Service = null;
private Singleton()
{ }
private static object lockThis = new object();
public static IOrganizationService Service
{
get
{
lock (lockThis)
{
if (_Service == null)
{
_Service = getService();
}
return _Service;
}
}
}
public static IOrganizationService getService()
{
ServerConnection serverConnect = new ServerConnection();
ServerConnection.Configuration config = serverConnect.GetServerConfiguration();
OrganizationServiceProxy _serviceProxy = null;
_serviceProxy = new OrganizationServiceProxy(config.OrganizationUri,
config.HomeRealmUri,
config.Credentials,
config.DeviceCredentials)
{ Timeout = TimeSpan.FromMilliseconds(200000) };
_serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
IOrganizationService service = (IOrganizationService)_serviceProxy;
return service;
}
}
Please suggest how this can be done better.