This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
tests/ServiceStack.OrmLite.Tests Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -174,6 +174,16 @@ public static int DeleteAll<T>(this IDbConnection dbConn)
174
174
return dbConn . Exec ( dbCmd => dbCmd . DeleteAll < T > ( ) ) ;
175
175
}
176
176
177
+ /// <summary>
178
+ /// Delete all rows provided. E.g:
179
+ /// <para>db.DeleteAll<Person>(people)</para>
180
+ /// </summary>
181
+ /// <returns>number of rows deleted</returns>
182
+ public static int DeleteAll < T > ( this IDbConnection dbConn , IEnumerable < T > rows )
183
+ {
184
+ return dbConn . Exec ( dbCmd => dbCmd . DeleteAll ( rows ) ) ;
185
+ }
186
+
177
187
/// <summary>
178
188
/// Delete all rows in the runtime table type. E.g:
179
189
/// <para>db.DeleteAll(typeof(Person))</para>
Original file line number Diff line number Diff line change @@ -642,6 +642,12 @@ internal static int DeleteAll<T>(this IDbCommand dbCmd)
642
642
return DeleteAll ( dbCmd , typeof ( T ) ) ;
643
643
}
644
644
645
+ internal static int DeleteAll < T > ( this IDbCommand dbCmd , IEnumerable < T > rows )
646
+ {
647
+ var ids = rows . Map ( x => x . GetId ( ) ) ;
648
+ return dbCmd . DeleteByIds < T > ( ids ) ;
649
+ }
650
+
645
651
internal static int DeleteAll ( this IDbCommand dbCmd , Type tableType )
646
652
{
647
653
return dbCmd . ExecuteSql ( dbCmd . GetDialectProvider ( ) . ToDeleteStatement ( tableType , null ) ) ;
Original file line number Diff line number Diff line change @@ -28,6 +28,25 @@ public void TearDown()
28
28
db . Dispose ( ) ;
29
29
}
30
30
31
+ [ Test ]
32
+ public void Can_delete_all_rows ( )
33
+ {
34
+ var row1 = ModelWithFieldsOfDifferentTypes . Create ( 1 ) ;
35
+ var row2 = ModelWithFieldsOfDifferentTypes . Create ( 2 ) ;
36
+ var row3 = ModelWithFieldsOfDifferentTypes . Create ( 3 ) ;
37
+
38
+ db . Save ( row1 ) ;
39
+ db . Save ( row2 ) ;
40
+ db . Save ( row3 ) ;
41
+
42
+ db . DeleteAll ( new [ ] { row1 , row3 } ) ;
43
+
44
+ var remaining = db . Select < ModelWithFieldsOfDifferentTypes > ( ) ;
45
+
46
+ Assert . That ( remaining . Count , Is . EqualTo ( 1 ) ) ;
47
+ Assert . That ( remaining [ 0 ] . Id , Is . EqualTo ( row2 . Id ) ) ;
48
+ }
49
+
31
50
[ Test ]
32
51
public void Can_Delete_from_ModelWithFieldsOfDifferentTypes_table ( )
33
52
{
You can’t perform that action at this time.
0 commit comments