dotConnect for Zoho CRM - EF unnecessary hits to api

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Cloud Applications
Post Reply
bob_vidabox
Posts: 9
Joined: Fri 13 Dec 2019 00:31

dotConnect for Zoho CRM - EF unnecessary hits to api

Post by bob_vidabox » Fri 13 Dec 2019 00:59

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

bob_vidabox
Posts: 9
Joined: Fri 13 Dec 2019 00:31

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

Post by bob_vidabox » Tue 17 Dec 2019 17:21

Is there anyone from Devart that can explain this behavior?

Shalex
Site Admin
Posts: 8941
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Tue 17 Dec 2019 19:27

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.

bob_vidabox
Posts: 9
Joined: Fri 13 Dec 2019 00:31

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

Post by bob_vidabox » Tue 17 Dec 2019 20:26

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?

Shalex
Site Admin
Posts: 8941
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Sat 21 Dec 2019 18:45

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.

bob_vidabox
Posts: 9
Joined: Fri 13 Dec 2019 00:31

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

Post by bob_vidabox » Sat 21 Dec 2019 21:33

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\""

bob_vidabox
Posts: 9
Joined: Fri 13 Dec 2019 00:31

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

Post by bob_vidabox » Mon 23 Dec 2019 19:39

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.

Shalex
Site Admin
Posts: 8941
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Wed 25 Dec 2019 14:18

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.

Shalex
Site Admin
Posts: 8941
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Mon 02 Mar 2020 13:26

GET /crm/v2/settings/related_lists?module=Accounts
Starting from v1.10.1098, this request is executed only once with your query.

Post Reply