I'm using Simple.OData.Client to query and update in our crm dynamics system. But each query, insertion or update takes up to 10 seconds. It works like a charm on postman. That means that the server is not the problem.
Here is my Code:
Base Class
public abstract class CrmBaseDao<T> where T : class
{
protected ODataClient GetClient()
{
return new ODataClient(new ODataClientSettings(BuildServiceUrl())
{
Credentials = new NetworkCredential(Settings.Default.CrmUsername, Settings.Default.CrmPassword),
IgnoreUnmappedProperties = true
});
}
public async Task<IEnumerable<T>> GetAll()
{
var client = GetClient();
return await client.For<T>().FindEntriesAsync();
}
private string BuildServiceUrl()
{
return Settings.Default.CrmBaseUrl + "/api/data/v8.2/";
}
}
Derived class:
public void Insert(Account entity)
{
var task = GetClient()
.For<Account>()
.Set(ConvertToAnonymousType(entity))
.InsertEntryAsync();
task.Wait();
entity.accountid = task.Result.accountid;
}
public void Update(Account entity)
{
var task = GetClient()
.For<Account>()
.Key(entity.accountid)
.Set(ConvertToAnonymousType(entity))
.UpdateEntryAsync();
task.Wait();
}
private object ConvertToAnonymousType(Account entity)
{
return new
{
entity.address1_city,
entity.address1_fax,
entity.address1_line1,
entity.address1_postalcode,
entity.address1_stateorprovince,
entity.he_accountnumber,
entity.name,
entity.telephone1,
entity.telephone2
};
}
public async Task<Account> GetByHeAccountNumber(string accountNumber)
{
return await GetClient().For<Account>()
.Filter(x => x.he_accountnumber == accountNumber)
.FindEntryAsync();
}
The call:
private void InsertIDocsToCrm()
{
foreach (var file in GetAllXmlFiles(Settings.Default.IDocPath))
{
var sapAccountEntity = GetSapAccountEntity(file);
var crmAccountEntity = AccountConverter.Convert(sapAccountEntity);
var existingAccount = crmAccountDao.GetByHeAccountNumber(crmAccountEntity.he_accountnumber);
existingAccount.Wait();
if (existingAccount.Result != null)
{
crmAccountEntity.accountid = existingAccount.Result.accountid;
crmAccountDao.Update(crmAccountEntity);
}
else
crmAccountDao.Insert(crmAccountEntity);
}
}
This whole function takes a very long time (30 sec+) Is there any chance to speed that up?
Additionaly it does take a lot of memory?!
Thanks
I suspect this might have to do with a size of schema. I will follow the issue you opened on GitHub.
UPDATE. I ran some benchmarks mocking server responses, and processing inside Simple.OData.Client took just milliseconds. I suggest you run benchmarks on a server side. You can also try assigning metadata file references to MetadataDocument property of ODataClientSettings.