Page 1 of 1

dotConnect for Zoho CRM - EF unnecessary hits to api

Posted: Fri 13 Dec 2019 00:59
by bob_vidabox
Recently started using dotConnect for Zoho CRM and have found that when using the Entity Framework the first call to the api after creating the DbContext sends off a lot of what I see as unnecessary calls. Something as simple as the code below requires 15 requests to the api. All the calls except the last one to the Records API would appear to be unnecessary as it is information that is already embodied in the entity model.

Any insight as to why all the additional calls to the api are happening?

Code: Select all

using (var context = GetZohoCrmContext())
{
    var account = await context.Accounts.SingleAsync(a => a.Website == "http://xyz.com");
    return account;
}
Requests
GET /crm/v2/settings/modules
GET /crm/v2/settings/related_lists?module=Leads
GET /crm/v2/settings/related_lists?module=Accounts
GET /crm/v2/settings/related_lists?module=Activities
GET /crm/v2/settings/related_lists?module=Calls
GET /crm/v2/settings/related_lists?module=Cases
GET /crm/v2/settings/related_lists?module=Contacts
GET /crm/v2/settings/related_lists?module=Events
GET /crm/v2/settings/related_lists?module=Invoices
GET /crm/v2/settings/related_lists?module=Products
GET /crm/v2/settings/related_lists?module=Sales_Orders
GET /crm/v2/settings/related_lists?module=Tasks
GET /crm/v2/settings/fields?module=Accounts
GET /crm/v2/settings/related_lists?module=Accounts
GET /crm/v2/Accounts/search?criteria=(Website:equals:http%3A%2F%2Fxyz.com)&per_page=2&page=1

Re: dotConnect for Zoho CRM - EF unnecessary hits to api

Posted: Tue 17 Dec 2019 17:21
by bob_vidabox
Is there anyone from Devart that can explain this behavior?

Re: dotConnect for Zoho CRM - EF unnecessary hits to api

Posted: Tue 17 Dec 2019 19:27
by Shalex
GET /crm/v2/settings/modules
Returns a list of standard objects.
GET /crm/v2/settings/related_lists?module=Leads
GET /crm/v2/settings/related_lists?module=Accounts
[...]
Returns related_lists fields for each standard object. The ADO.NET provider extends standard objects with the corresponding fields.

This is required for initializing provider internal metadata of available objects. These queries are executed only once when the underlying ADO.NET connection is opened. You can create and open ZohoConnection in your code to read metadata, then pass it to your context.

Re: dotConnect for Zoho CRM - EF unnecessary hits to api

Posted: Tue 17 Dec 2019 20:26
by bob_vidabox
I know what the calls are, but it still isn't clear to me why the calls are needed, at least in our case. We are using a database first approach using and edmx model and the EF6 provider. All of the metadata in those requests are already included in the edm model.

Can you provide an example of how the metadata is to be passed to the dbcontext so that the additional calls aren't required at the start of every business transaction using the dbcontext?

Re: dotConnect for Zoho CRM - EF unnecessary hits to api

Posted: Sat 21 Dec 2019 18:45
by Shalex
bob_vidabox wrote:
Tue 17 Dec 2019 20:26
Can you provide an example of how the metadata is to be passed to the dbcontext so that the additional calls aren't required at the start of every business transaction using the dbcontext?
In case of XML mapping, you should create EntityConnection object and pass it to the context constructor: https://docs.microsoft.com/en-us/dotnet ... onnection_.

With fluent mapping, the context constructor accepts ADO.NET connection.

The DbContext template of Devart Entity Model (*.edml) allows using both XML and fluent mapping: https://blog.devart.com/entity-develope ... plate.html.

Re: dotConnect for Zoho CRM - EF unnecessary hits to api

Posted: Sat 21 Dec 2019 21:33
by bob_vidabox
That is already being done. Without the edm data or using the fluent api the db context would have no idea how to map from the conceptual to the relational model. That isn't the issue here. The issue is is that calls are being made that were already called to create the edm model (i.e. the XML mapping) to begin with.

Connection String
metadata=res://*/Entities.ZohoCrmModel.csdl|res://*/Entities.ZohoCrmModel.ssdl|res://*/Entities.ZohoCrmModel.msl;provider=Devart.Data.Zoho;provider connection string=\"Use Display Name For Custom Tables=True;API Version=v2;Client Id=xxx;Client Secret=xxx;Refresh Token=xxx\""

Re: dotConnect for Zoho CRM - EF unnecessary hits to api

Posted: Mon 23 Dec 2019 19:39
by bob_vidabox
The reason why this is important is because you have limits on the number of api calls per day you are allowed. Having this many unnecessary calls to the api can significantly contribute to maxing out the daily api call limit.

One way to handle this would be to have a context lifetime of the application (bad practice) and use AsNoTracking() for all entities and manually handle change tracking. This would limit the unnecessary calls to the first query and first time query on entities since additional metadata is also requested when an entity is first queried. This could lead to problems though and it would be better if the only calls to the api were those that were needed.

Re: dotConnect for Zoho CRM - EF unnecessary hits to api

Posted: Wed 25 Dec 2019 14:18
by Shalex
The internal implementation of dotConnect for Zoho CRM requires the full list of available tables including related lists on a per-connection basis. We do not have a technical possibility to change this behavior for cloud-based service.

Any EF provider works via ADO.NET provider. And all ADO.NET providers do not depend on the metadata of the EF level.

Re: dotConnect for Zoho CRM - EF unnecessary hits to api

Posted: Mon 02 Mar 2020 13:26
by Shalex
GET /crm/v2/settings/related_lists?module=Accounts
Starting from v1.10.1098, this request is executed only once with your query.