/// <summary>
        /// Determines dialect for a connection
        /// </summary>
        /// <param name="connectionKey">Connection key</param>
        /// <param name="entry">Connection entry</param>
        protected virtual ISqlDialect DetermineDialect(string connectionKey, ConnectionStringEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            if (entry.DialectInstance != null)
            {
                return(entry.DialectInstance);
            }

            if (!string.IsNullOrEmpty(entry.Dialect))
            {
                var dialectType = Type.GetType("Serenity.Data." + entry.Dialect + "Dialect") ??
                                  Type.GetType("Serenity.Data." + entry.Dialect) ??
                                  Type.GetType(entry.Dialect);

                if (dialectType == null)
                {
                    throw new ArgumentException($"Dialect type {entry.Dialect} specified for connection {connectionKey} is not found!");
                }

                return((ISqlDialect)Activator.CreateInstance(dialectType));
            }

            return(dialectByProviderName.TryGetValue(entry.ProviderName, out ISqlDialect dialect) ?
                   dialect : SqlSettings.DefaultDialect);
        }
Beispiel #2
0
        /// <summary>
        /// Determines dialect for a connection
        /// </summary>
        /// <param name="connectionKey">Connection key</param>
        /// <param name="entry">Connection entry</param>
        protected virtual ISqlDialect DetermineDialect(string connectionKey, ConnectionStringEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            if (entry.DialectInstance != null)
            {
                return(entry.DialectInstance);
            }

            if (string.IsNullOrEmpty(entry.Dialect))
            {
                return(sqlDialectMapper.TryGet(entry.ProviderName) ?? SqlSettings.DefaultDialect);
            }

            return(sqlDialectMapper.TryGet(entry.Dialect) ??
                   throw new ArgumentException($"Dialect type {entry.Dialect} specified for connection {connectionKey} is not found!"));
        }