2020
2121#elif EF6
2222using System . Data . Entity . Core . Objects ;
23+ using System . Data . Entity . Infrastructure . Interception ;
2324using Z . EntityFramework . Plus . Internal . Core . SchemaObjectModel ;
2425
2526#elif EFCORE
@@ -173,7 +174,8 @@ public int Execute<T>(IQueryable<T> query) where T : class
173174
174175 // GET model and info
175176#if EF5 || EF6
176- var model = query . GetDbContext ( ) . GetModel ( ) ;
177+ var dbContext = query . GetDbContext ( ) ;
178+ var model = dbContext . GetModel ( ) ;
177179 var entity = model . Entity < T > ( ) ;
178180 var keys = entity . Info . Key . PropertyRefs ;
179181
@@ -206,6 +208,7 @@ public int Execute<T>(IQueryable<T> query) where T : class
206208 Executing ( command ) ;
207209 }
208210
211+ #if EF5
209212 if ( command . GetType ( ) . Name == "NpgsqlCommand" )
210213 {
211214 command . CommandText = command . CommandText . Replace ( "[" , "\" " ) . Replace ( "]" , "\" " ) ;
@@ -232,6 +235,36 @@ public int Execute<T>(IQueryable<T> query) where T : class
232235 var rowAffecteds = ( int ) command . ExecuteScalar ( ) ;
233236 return rowAffecteds ;
234237 }
238+ #elif EF6
239+ var interceptionContext = new DbCommandInterceptionContext ( dbContext . GetObjectContext ( ) . GetInterceptionContext ( ) ) ;
240+
241+ if ( command . GetType ( ) . Name == "NpgsqlCommand" )
242+ {
243+ command . CommandText = command . CommandText . Replace ( "[" , "\" " ) . Replace ( "]" , "\" " ) ;
244+ int totalRowAffecteds = DbInterception . Dispatch . Command . NonQuery ( command , interceptionContext ) ;
245+ return totalRowAffecteds ;
246+ }
247+ else if ( command . Connection . GetType ( ) . Name . Contains ( "MySql" ) )
248+ {
249+ int totalRowAffecteds = DbInterception . Dispatch . Command . NonQuery ( command , interceptionContext ) ;
250+ return totalRowAffecteds ;
251+ }
252+ else if ( command . Connection . GetType ( ) . Name . Contains ( "Oracle" ) )
253+ {
254+ int totalRowAffecteds = DbInterception . Dispatch . Command . NonQuery ( command , interceptionContext ) ;
255+ return totalRowAffecteds ;
256+ }
257+ else if ( command . GetType ( ) . Name == "SqlCeCommand" )
258+ {
259+ int totalRowAffecteds = DbInterception . Dispatch . Command . NonQuery ( command , interceptionContext ) ;
260+ return totalRowAffecteds ;
261+ }
262+ else
263+ {
264+ var rowAffecteds = ( int ) DbInterception . Dispatch . Command . Scalar ( command , interceptionContext ) ;
265+ return rowAffecteds ;
266+ }
267+ #endif
235268
236269 }
237270 finally
@@ -300,7 +333,7 @@ public int Execute<T>(IQueryable<T> query) where T : class
300333 }
301334 }
302335#endif
303- }
336+ }
304337
305338#if EF5 || EF6
306339 /// <summary>Creates a command to execute the batch operation.</summary>
0 commit comments