Ejemplo n.º 1
0
        public static void InstallSqlTable(string connectionString, SqlServerSlugStoreOptions options)
        {
            var script = GetStringResource(typeof(SqlServerSlugStore).GetTypeInfo().Assembly, "SlugHub.SqlServer.Install.sql");

            //do replaces
            script = script.Replace("$(SCHEMA_NAME)", options.TableSchema);
            script = script.Replace("$(TABLE_NAME)", options.TableName);

            using (var connection = new SqlConnection(connectionString))
            {
                for (var i = 0; i < 5; i++)
                {
                    try
                    {
                        connection.Execute(script);
                        break;
                    }
                    catch (SqlException ex)
                    {
                        if (ex.Number == 1205)
                        {
                            //no trace in .net standard
                            //Trace.WriteLine("Deadlock occurred during automatic migration execution. Retrying...");
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
        }
        public SqlServerSlugStore(string connectionString, SqlServerSlugStoreOptions options = null)
        {
            if (options == null)
            {
                options = new SqlServerSlugStoreOptions();
            }

            _options          = options;
            _connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));

            Installer.InstallSqlTable(_connectionString, _options);
        }