views:

174

answers:

2

What is the best way in terms of speed of the platform and maintainability to access data (read only) on CRM 4? I've done all three, but interested in the opinions of the crowd.

  • Via the API
  • Via the webservices directly
  • Via DB calls to the views

...and why?

My thoughts normally center around DB calls to the views but I know there are purists out there.

+2  A: 

Given both requirements I'd say you want to call the views. Properly crafted SQL queries will fly.

Going through the API is required if you plan to modify data, but it isnt the fastest approach around because it doesnt allow deep loading of entities. For instance if you want to look at customers and their orders you'll have to load both up individually and then join them manually. Where as a SQL query will already have the data joined.

Nevermind that the TDS stream is a lot more effecient that the SOAP messages being used by the API & webservices.

UPDATE

I should point out in regard to the views and CRM database in general: CRM does not optimize the indexes on the tables or views for custom entities (how could it?). So if you have a truckload entity that you lookup by destination all the time you'll need to add an index for that property. Depending upon your application it could make a huge difference in performance.

Jake
+1  A: 

I'll add to jake's comment by saying that querying against the tables directly instead of the views (*base & *extensionbase) will be even faster.

In order of speed it'd be:

  1. direct table query
  2. view query
  3. filterd view query
  4. api call
Focus
thanks a bunch!
Derek
Be careful going directly against the tables. The views enforce security which won't happen going directly to the tables. Also, doing updates directly against the tables is a super bad idea. All updates must go through the API. Sucksville if you have a lot of data, but failure to do so can have unpredicable results.
Jake
I'd never recommend doing any direct updates or inserts via tables or views. However, for large scale applications (in the hundreds of users and millions of rows) the api just won't cut it for querying purposes. If you need security roles to be enforced, then yes you will HAVE to go against either the API or Filtered views. Both of which are rather slow when extracting large amounts of data.
Focus