Twitter Image

On the maximum number of entities

Written by Stéphane Dorrekens
Tuesday, 27 September 2011 14:09

I was recently working on a project where one of the possible paths of solution was to create a lot (ie: hundreds) of custom entities in a single CRM organisation.
There's an enforced limit of 200 custom entities in CRM Online but for On Premise, the number of entities should technically only be limited by the number of objects allowed in an SQL Database (2 147 483 647 for both SQL 2008 and 2005) and as a simple entity only consumes 4 objects (2 tables and 2 views), we should have plenty of room.

But then I remembered reading this article by seb determining that the maximum number of attributes in CRM 2011 is hardcoded at 1000, and started having a doubt about a maximum number of entities in Dynamics CRM on Premise (there's an enforced limit in CRM online after all)
A quick look on the web found nothing, so I did resolve to find out the "hard way".
Helpfully, the sdk provides a code sample for entity creation (both in the CRM 2011 sdk and the CRM 4.0 sdk), so it's just a matter of adapting it with a loop.

Here're the results of the findings

CRM 2011 On Premise
As you can see herebelow there's doesn't seems to be hardcoded limits on the On Premise number of custom entities (or at least it is more than 1000).

 

CRM 4.0 On Premise
There doesn't seems to be any hardcoded limits in CRM 4.0 On Premise as well, as you can see in the following screenshots

 

Here're the code snippets used for the tests.

CRM 2011

        public void RuntheShow(ServerConnection.Configuration serverConfig, bool promptForDelete)
        {
                using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri,
                                                                    serverConfig.HomeRealmUri,
                                                                                                                 serverConfig.Credentials,
                                                                    serverConfig.DeviceCredentials))

                {
                    _serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
                    string theName;
                    for (int i = 1; i < 2000; i++)
                    {
                        theName=("Entity_"+i.ToString().PadLeft(4,'0'));
                        Console.Write("Creating Entity " + theName);
                        _serviceProxy.Execute(GetCreateRequest(theName));
                        Console.WriteLine("done.");
                    }

                }
         }      

   public CreateEntityRequest GetCreateRequest(string theName)
        {
            CreateEntityRequest createrequest = new CreateEntityRequest
            {
                Entity = new EntityMetadata
                {
                    SchemaName = theName,
                    DisplayName = new Label(theName, 1033),
                    DisplayCollectionName = new Label(theName+"s", 1033),
                    Description = new Label(theName, 1033),
                    OwnershipType = OwnershipTypes.UserOwned,
                    IsActivity = false,
                },                PrimaryAttribute = new StringAttributeMetadata
                {
                    SchemaName = "new_name",
                    RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
                    MaxLength = 100,
                    Format = StringFormat.Text,
                    DisplayName = new Label(theName+" Name", 1033),
                    Description = new Label("The primary attribute for the "+theName+" entity.", 1033)
                }
            };

            return createrequest;

        }

CRM 4.0
        static public void RuntheShow()   
        {
        CrmAuthenticationToken token = new CrmAuthenticationToken();
        token.OrganizationName = "test";
        token.AuthenticationType = 0;  

        metadataService = new MetadataService();
        metadataService.Url = http://localhost/MSCRMServices/2007/MetadataService.asmx;
        metadataService.CrmAuthenticationTokenValue = token;
        metadataService.Credentials = System.Net.CredentialCache.DefaultCredentials;
        metadataService.PreAuthenticate = true;

        for (int i = 1; i < 2000; i++)
            CreateSingleEntity("Entity_" + i.ToString().PadLeft(4,'0'));
        }

     public static void CreateSingleEntity (string theName)
     {
         try
         {
             Console.Write("Creating Entity {0}...", theName);
             EntityMetadata timesheetEntity = new EntityMetadata();
             timesheetEntity.SchemaName = theName;
             timesheetEntity.OwnershipType = new CrmOwnershipTypes();
             timesheetEntity.OwnershipType.Value = OwnershipTypes.UserOwned;
             timesheetEntity.DisplayName = CreateSingleLabel(theName, 1033);
             timesheetEntity.DisplayCollectionName = CreateSingleLabel(theName+"s", 1033);
             timesheetEntity.Description = CreateSingleLabel(theName, 1033);

             StringAttributeMetadata primaryAttribute = new StringAttributeMetadata();
             primaryAttribute.SchemaName = "new_name";
             primaryAttribute.RequiredLevel = new CrmAttributeRequiredLevel();
             primaryAttribute.RequiredLevel.Value = AttributeRequiredLevel.None;
             primaryAttribute.MaxLength = new CrmNumber();
             primaryAttribute.MaxLength.Value = 100;
             primaryAttribute.DisplayName = CreateSingleLabel("Name", 1033);
             primaryAttribute.Description = CreateSingleLabel("Name", 1033);

             CreateEntityRequest createEntity = new CreateEntityRequest();
             createEntity.Entity = timesheetEntity;
             createEntity.HasActivities = false;
             createEntity.HasNotes = true;
             createEntity.PrimaryAttribute = primaryAttribute;

             CreateEntityResponse entityResponse = (CreateEntityResponse )metadataService.Execute(createEntity);
                Console.WriteLine("done");
        }
     }

      public static CrmLabel CreateSingleLabel(string label, int langCode)
      {
         CrmNumber crmNumber = new CrmNumber();
         crmNumber.Value = langCode;
         LocLabel locLabel = new LocLabel();
         locLabel.LanguageCode = crmNumber;
         locLabel.Label = label;
         CrmLabel crmLabel = new CrmLabel();
         crmLabel.LocLabels = new LocLabel[] { locLabel };
         return crmLabel;
      }
   }

Comments  

 
#3 Dave 2012-03-19 09:46
Thanks.

Dave
 
 
#2 S.Dorrekens 2012-03-08 09:56
Hi Dave,
I was a while back, so I don't have the exact figures but it took quite a while (at least a couple hours, maybe 3).
This said I ran it on a virtual box on my laptop where CRM Performance is usually bad.
As far as I remembered there was no significant degradation over time.
 
 
#1 Dave 2012-03-07 15:46
I came across your code snippet when searching for help on an issue we have. We have written a test harness to do the same as your code does and the performance degrades significantly as we get to 181 entities created. This may be an environmental issue but I just wondered how quickly your code executed to create 1000 entities in CRM 2011??

Thanks

D