Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit c65920a

Browse files
committed
Merge pull request #436 from KevinHoward/master
Updated DropForeignKey<T> to use dialect provider
2 parents ac248fb + a9fda0d commit c65920a

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/ServiceStack.OrmLite/OrmLiteSchemaModifyApi.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void AlterTable<T>(this IDbConnection dbConn, string command)
2222

2323
public static void AlterTable(this IDbConnection dbConn, Type modelType, string command)
2424
{
25-
string sql = string.Format("ALTER TABLE {0} {1};",
25+
var sql = string.Format("ALTER TABLE {0} {1};",
2626
dbConn.GetDialectProvider().GetQuotedTableName(modelType.GetModelDefinition()),
2727
command);
2828
dbConn.ExecuteSql(sql);
@@ -84,9 +84,10 @@ public static void DropColumn<T>(this IDbConnection dbConn, string columnName)
8484

8585
public static void DropColumn(this IDbConnection dbConn, Type modelType, string columnName)
8686
{
87-
string command = string.Format("ALTER TABLE {0} DROP {1};",
88-
dbConn.GetDialectProvider().GetQuotedTableName(modelType.GetModelDefinition().ModelName),
89-
dbConn.GetDialectProvider().GetQuotedName(columnName));
87+
var provider = dbConn.GetDialectProvider();
88+
var command = string.Format("ALTER TABLE {0} DROP {1};",
89+
provider.GetQuotedTableName(modelType.GetModelDefinition().ModelName),
90+
provider.GetQuotedName(columnName));
9091

9192
dbConn.ExecuteSql(command);
9293
}
@@ -100,7 +101,7 @@ public static void AddForeignKey<T, TForeign>(this IDbConnection dbConn,
100101
OnFkOption onDelete,
101102
string foreignKeyName = null)
102103
{
103-
string command = dbConn.GetDialectProvider().ToAddForeignKeyStatement(field,
104+
var command = dbConn.GetDialectProvider().ToAddForeignKeyStatement(field,
104105
foreignField,
105106
onUpdate,
106107
onDelete,
@@ -111,9 +112,11 @@ public static void AddForeignKey<T, TForeign>(this IDbConnection dbConn,
111112

112113
public static void DropForeignKey<T>(this IDbConnection dbConn, string foreignKeyName)
113114
{
114-
string command = string.Format("ALTER TABLE {0} DROP FOREIGN KEY {1};",
115-
dbConn.GetDialectProvider().GetQuotedTableName(ModelDefinition<T>.Definition.ModelName),
116-
dbConn.GetDialectProvider().GetQuotedName(foreignKeyName));
115+
var provider = dbConn.GetDialectProvider();
116+
var modelDef = ModelDefinition<T>.Definition;
117+
var command = string.Format(provider.GetDropForeignKeyConstraints(modelDef),
118+
provider.GetQuotedTableName(modelDef.ModelName),
119+
provider.GetQuotedName(foreignKeyName));
117120
dbConn.ExecuteSql(command);
118121
}
119122

@@ -128,9 +131,10 @@ public static void CreateIndex<T>(this IDbConnection dbConn, Expression<Func<T,
128131

129132
public static void DropIndex<T>(this IDbConnection dbConn, string indexName)
130133
{
131-
string command = string.Format("ALTER TABLE {0} DROP INDEX {1};",
132-
dbConn.GetDialectProvider().GetQuotedTableName(ModelDefinition<T>.Definition.ModelName),
133-
dbConn.GetDialectProvider().GetQuotedName(indexName));
134+
var provider = dbConn.GetDialectProvider();
135+
var command = string.Format("ALTER TABLE {0} DROP INDEX {1};",
136+
provider.GetQuotedTableName(ModelDefinition<T>.Definition.ModelName),
137+
provider.GetQuotedName(indexName));
134138
dbConn.ExecuteSql(command);
135139
}
136140

0 commit comments

Comments
 (0)