@@ -22,7 +22,7 @@ public static void AlterTable<T>(this IDbConnection dbConn, string command)
22
22
23
23
public static void AlterTable ( this IDbConnection dbConn , Type modelType , string command )
24
24
{
25
- string sql = string . Format ( "ALTER TABLE {0} {1};" ,
25
+ var sql = string . Format ( "ALTER TABLE {0} {1};" ,
26
26
dbConn . GetDialectProvider ( ) . GetQuotedTableName ( modelType . GetModelDefinition ( ) ) ,
27
27
command ) ;
28
28
dbConn . ExecuteSql ( sql ) ;
@@ -84,9 +84,10 @@ public static void DropColumn<T>(this IDbConnection dbConn, string columnName)
84
84
85
85
public static void DropColumn ( this IDbConnection dbConn , Type modelType , string columnName )
86
86
{
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 ) ) ;
90
91
91
92
dbConn . ExecuteSql ( command ) ;
92
93
}
@@ -100,7 +101,7 @@ public static void AddForeignKey<T, TForeign>(this IDbConnection dbConn,
100
101
OnFkOption onDelete ,
101
102
string foreignKeyName = null )
102
103
{
103
- string command = dbConn . GetDialectProvider ( ) . ToAddForeignKeyStatement ( field ,
104
+ var command = dbConn . GetDialectProvider ( ) . ToAddForeignKeyStatement ( field ,
104
105
foreignField ,
105
106
onUpdate ,
106
107
onDelete ,
@@ -111,9 +112,11 @@ public static void AddForeignKey<T, TForeign>(this IDbConnection dbConn,
111
112
112
113
public static void DropForeignKey < T > ( this IDbConnection dbConn , string foreignKeyName )
113
114
{
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 ) ) ;
117
120
dbConn . ExecuteSql ( command ) ;
118
121
}
119
122
@@ -128,9 +131,10 @@ public static void CreateIndex<T>(this IDbConnection dbConn, Expression<Func<T,
128
131
129
132
public static void DropIndex < T > ( this IDbConnection dbConn , string indexName )
130
133
{
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 ) ) ;
134
138
dbConn . ExecuteSql ( command ) ;
135
139
}
136
140
0 commit comments