What are the (dis)advantages of early bound?

前端 未结 2 1826
自闭症患者
自闭症患者 2021-02-02 01:32

I\'m researching the pros and cons of early and late binding in CRM. I\'ve got a good idea on the subject but there are some points I\'m unclear about.

  1. Some say

2条回答
  •  半阙折子戏
    2021-02-02 01:58

    1. Probably not. If you want to know for certain, I would suggest running some tests and profiling the results.

    However these MSDN articles suggest late binding it faster.

    Best Practices for Developing with Microsoft Dynamics CRM

    Use Early-Bound Types

    Use the Entity class when your code must work on entities and attributes that are not known at the time the code is written. In addition, if your custom code works with thousands of entity records, use of the Entity class results in slightly better performance than the early-bound entity types. However, this flexibility has a disadvantage because you cannot verify entity and attribute names at compile time. If your entities are already defined at code time and slight performance degradation is acceptable, you should use the early-bound types that you can generate by using the CrmSvcUtil tool. For more information, see Use the Early Bound Entity Classes in Code.

    Choose your Development Style for Managed Code for Microsoft Dynamics CRM

    Entity Programming (Early Bound vs. Late Bound vs. Developer Extensions)

    Early Bound ... Serialization costs increase as the entities are converted to late bound types during transmission over the network.

    2 & 3. You don't have to take any special action with custom fields or entities. Svcutil will generate classes for both.

    Use the Early Bound Entity Classes in Code

    The class created by the code generation tool includes all the entity’s attributes and relationships. By using the class in your code, you can access these attributes and be type safe. A class with attributes and relationships is created for all entities in your organization. There is no difference between the generated types for system and custom entities.

    As a side note, I wouldn't get too hung up on it, they are both acceptable implementation approaches and in the majority of situations I doubt the performance impact will be significant enough to worry about. Personally I prefer late binding, but that's mostly because I don't like having to generate the classes.


    Edit.

    I performed some quick profiling on this by creating accounts in CRM, a set of 200 & 5000. It confirms the information provided by Microsoft, in both runs late binding was about 8.5 seconds quicker. Over very short runs the late binding is significantly faster - 90%. However early binding quickly picks up speed and by the time 5000 records are created late binding is only 2% faster.

    Short Run

    Short Run Data

    Long Run

    Long Run Data

    Full details blogged here.

提交回复
热议问题