web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Early binding vs Late Binding in Ms Crm - c#

(0) ShareShare
ReportReport
Posted on by

Hello guys ,

I wanted to know in general - when to use early binding and when to use late binding

For example , I want to create new record in Ms Crm by c# :

Code snippet 1 (Late binding) :

Entity e =new Entity();

e.LogicalName = "account";

e.Attributes["new_firstname"] = "data";

_serviceProxy.Create(e);

Code snippet 2 (Early binding) :

Account account = new Account { FirstName = "data" };

_serviceProxy.Create(account);

I would appreciate any suggestions regarding this.

Thanks ,
Om

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    early binding is practically a wrapper around to the standard classes to speed up the development.

    It has also some bonus like the possibility to use LINQ.

    You can always choose both, there are no limitations. Personally I prefer late bound, especially for plugin development.

  • Community Member Profile Picture
    on at

    Hello Guido ,

    I thought late binding gives slightly better performance than early.

    (Correct me if I am wrong)

    Thanks for your valuable response.

    Regards ,

    Om

  • Verified answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    Yes, late bound is faster than early bound, but if your application doesn't require speed performances this is not the main criteria to choose between late bound and early bound.

  • Community Member Profile Picture
    on at

    Hello Guido ,

    Thanks for valuable response.

    Regards ,

    Om

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Hi Guido & Om,

    There is a common miss-conception that early bounding has a speed penalty which I think is a hang up from CRM4 days. Ever since CRM2011 there isn't any difference in real terms since the early bound classes are simply performing the same actions that your code would have to any way (setting/getting attributes). It is true that the early bound classes will make your plugin slightly bigger in size - but you can always trim down the generated classes to only the ones you need.

    Because of the many advantages of early bound classes IMHO there is no reason *not* to use them!

    Hope this helps,

    Scott

  • Verified answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    Hi Scott,

    Microsoft says that "use of the Entity class results in slightly better performance than the early-bound entity types." (from msdn.microsoft.com/.../gg509027.aspx)

    there are also some tests regarding this, the one that I "trust" more is this one:

    woodsworkblog.wordpress.com/.../crm-2011-early-binding-vs-late-binding-performance

    there was also a discussion on the facebook dynamics crm group about this, but I can't find it right now.

    However isn't so important, (next phrase is common in Italy) it's like deciding if the angels are boys or girls.

  • Suggested answer
    Jaymin Profile Picture
    70 on at

    I agree with Scott. Since inception of CRM 2011, there is not much difference in performance between early binding and late binding.

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Thanks for the link Guido - I hadn't seen that post from James before and it's very interesting.

    I think the results do look a bit miss-leading though. The 'short' run tests will be mainly influenced by the Reflection that goes on when the Organization Service hooks up the early bound classes.  This should then be cached and so hence the % impact on the overall run time goes down as the records increase. An improvement to the tests that James has run would be to have a 'warm up' period before the measurements are taken.

    Perhaps I should revise my "isn't any difference in real terms" statement, but I still believe the Early bound classes shouldn't be avoided due to performance reasons since the high through put scenarios where it performance counts will be exactly the same scenarios where the overhead will be minimal overall.

    I have seen code made considerably more complex and with many more bugs in it due to premature optimisation due to the belief that early bound types should be avoided for performance reasons!

    Thanks again for an interesting discussion :)

    Hope this helps,

    Scott

  • ScottDurow Profile Picture
    21 on at

    I simply couldn't resist looking into this more - develop1.net/.../Early-Binding-vs-Late-Binding-Performance-Revisited.aspx

    Interesting results!

  • Community Member Profile Picture
    on at

    Hi,

    Please refer to below given article-:

    woodsworkblog.wordpress.com/.../crm-2011-early-binding-vs-late-binding-performance

    Mark as verified if helpful.

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans