/// <summary>
        /// Creates the specified database info.
        /// </summary>
        /// <param name="optionalSettings">The settings to be used.</param>
        /// <returns></returns>
        public static LocalCrmDatabaseInfo Create <T>(LocalCrmDatabaseOptionalSettings optionalSettings)
        {
            var contextType = typeof(T);

            if (contextType.Name == "OrganizationServiceContext")
            {
                throw new Exception("Must pass in a derived type from Microsoft.Xrm.Sdk.Client.OrganizationServiceContext");
            }

            return(Create(contextType.Assembly, contextType.Namespace, optionalSettings));
        }
        /// <summary>
        /// Creates the specified database info.
        /// </summary>
        /// <param name="earlyBoundAssembly">The early bound assembly.</param>
        /// <param name="earlyBoundNamespace">The early bound namespace.</param>
        /// <param name="optionalSettings">The settings to be used.</param>
        /// <returns></returns>
        public static LocalCrmDatabaseInfo Create(Assembly earlyBoundAssembly,
                                                  string earlyBoundNamespace,
                                                  LocalCrmDatabaseOptionalSettings optionalSettings)
        {
            optionalSettings = optionalSettings ?? new LocalCrmDatabaseOptionalSettings();
            var dbName = optionalSettings.DatabaseName ?? string.Empty;

            return(new LocalCrmDatabaseInfo
            {
                BusinessUnit = GetRef(optionalSettings.BusinessUnitId, Test.Entities.BusinessUnit.EntityLogicalName, AppConfig.CrmSystemSettings.BusinessUnitId),
                DatabaseName = dbName,
                EarlyBoundEntityAssembly = earlyBoundAssembly,
                EarlyBoundNamespace = earlyBoundNamespace,
                FullNameFormat = optionalSettings.FullNameFormat ?? AppConfig.CrmSystemSettings.FullNameFormat,
                LanguageCode = optionalSettings.LanguageCode ?? AppConfig.DefaultLanguageCode,
                User = GetRef(optionalSettings.UserId, Test.Entities.SystemUser.EntityLogicalName, AppConfig.CrmSystemSettings.UserId),
                UserOnBehalfOf = GetRef(optionalSettings.UserOnBehalfOfId, Test.Entities.SystemUser.EntityLogicalName, AppConfig.CrmSystemSettings.OnBehalfOfId),
                OrganizationId = optionalSettings.OrganizationId ?? ConvertToGuid(dbName),
                PrimaryNameProvider = optionalSettings.PrimaryNameProvider ?? PrimaryNameFieldProviderBase.GetConfiguredProvider(earlyBoundAssembly, earlyBoundNamespace),
                ManyToManyAssociationProvider = optionalSettings.ManyToManyAssociationProvider ?? new Many2ManyAssociationProvider(AppConfig.CrmEntities.Many2ManyAssociationDefinitions)
            });
        }