11using System ;
22using System . Collections . Generic ;
3+ using System . Diagnostics . Contracts ;
34using System . Linq ;
45using System . Threading ;
56using System . Threading . Tasks ;
@@ -17,6 +18,9 @@ public static partial class TableMapping
1718 /// <typeparam name="T">The mapped type</typeparam>
1819 public static IStatement PrepareDeleteStatement < T > ( this IDatabaseConnection This , ITableMapping < T > tableMapping )
1920 {
21+ Contract . Requires ( This != null ) ;
22+ Contract . Requires ( tableMapping != null ) ;
23+
2024 return This . PrepareDelete ( tableMapping . TableName , tableMapping . PrimaryKeyColumn ( ) ) ;
2125 }
2226
@@ -48,6 +52,9 @@ private static IEnumerable<KeyValuePair<long,T>> YieldDeleteAll<T>(this IDatabas
4852 /// <typeparam name="T">The mapped type.</typeparam>
4953 public static bool TryDelete < T > ( this IDatabaseConnection This , ITableMapping < T > tableMapping , long primaryKey , out T deleted )
5054 {
55+ Contract . Requires ( This != null ) ;
56+ Contract . Requires ( tableMapping != null ) ;
57+
5158 var result = This . YieldDeleteAll ( tableMapping , new long [ ] { primaryKey } ) . FirstOrDefault ( ) ;
5259 if ( result . Value != null )
5360 {
@@ -71,6 +78,10 @@ public static bool TryDelete<T>(this IDatabaseConnection This, ITableMapping<T>
7178 /// <typeparam name="T">The mapped type.</typeparam>
7279 public static IReadOnlyDictionary < long , T > DeleteAll < T > ( this IDatabaseConnection This , ITableMapping < T > tableMapping , IEnumerable < long > primaryKeys )
7380 {
81+ Contract . Requires ( This != null ) ;
82+ Contract . Requires ( tableMapping != null ) ;
83+ Contract . Requires ( primaryKeys != null ) ;
84+
7485 return This . RunInTransaction ( _ =>
7586 This . YieldDeleteAll ( tableMapping , primaryKeys )
7687 . Where ( kvp => kvp . Value != null )
@@ -88,6 +99,10 @@ public static IReadOnlyDictionary<long,T> DeleteAll<T>(this IDatabaseConnection
8899 /// <typeparam name="T">The mapped type.</typeparam>
89100 public static Task < IReadOnlyDictionary < long , T > > DeleteAllAsync < T > ( this IAsyncDatabaseConnection This , ITableMapping < T > tableMapping , IEnumerable < long > primaryKeys , CancellationToken ct )
90101 {
102+ Contract . Requires ( This != null ) ;
103+ Contract . Requires ( tableMapping != null ) ;
104+ Contract . Requires ( primaryKeys != null ) ;
105+
91106 return This . Use ( ( db , _ ) => db . DeleteAll < T > ( tableMapping , primaryKeys ) , ct ) ;
92107 }
93108
@@ -101,6 +116,10 @@ public static Task<IReadOnlyDictionary<long,T>> DeleteAllAsync<T>(this IAsyncDat
101116 /// <typeparam name="T">The mapped type.</typeparam>
102117 public static Task < IReadOnlyDictionary < long , T > > DeleteAllAsync < T > ( this IAsyncDatabaseConnection This , ITableMapping < T > tableMapping , IEnumerable < long > primaryKeys )
103118 {
119+ Contract . Requires ( This != null ) ;
120+ Contract . Requires ( tableMapping != null ) ;
121+ Contract . Requires ( primaryKeys != null ) ;
122+
104123 return This . DeleteAllAsync ( tableMapping , primaryKeys , CancellationToken . None ) ;
105124 }
106125
@@ -112,6 +131,9 @@ public static Task<IReadOnlyDictionary<long,T>> DeleteAllAsync<T>(this IAsyncDat
112131 /// <typeparam name="T">The mapped type.</typeparam>
113132 public static void DeleteAllRows < T > ( this IDatabaseConnection This , ITableMapping < T > tableMapping )
114133 {
134+ Contract . Requires ( This != null ) ;
135+ Contract . Requires ( tableMapping != null ) ;
136+
115137 This . DeleteAll ( tableMapping . TableName ) ;
116138 }
117139
@@ -125,6 +147,9 @@ public static void DeleteAllRows<T>(this IDatabaseConnection This, ITableMapping
125147 /// <typeparam name="T">The mapped type.</typeparam>
126148 public static Task DeleteAllRowsAsync < T > ( this IAsyncDatabaseConnection This , ITableMapping < T > tableMapping , CancellationToken ct )
127149 {
150+ Contract . Requires ( This != null ) ;
151+ Contract . Requires ( tableMapping != null ) ;
152+
128153 return This . Use ( ( db , _ ) => db . DeleteAllRows ( tableMapping ) , ct ) ;
129154 }
130155
@@ -137,6 +162,9 @@ public static Task DeleteAllRowsAsync<T>(this IAsyncDatabaseConnection This, ITa
137162 /// <typeparam name="T">The mapped type.</typeparam>
138163 public static Task DeleteAllRowsAsync < T > ( this IAsyncDatabaseConnection This , ITableMapping < T > tableMapping )
139164 {
165+ Contract . Requires ( This != null ) ;
166+ Contract . Requires ( tableMapping != null ) ;
167+
140168 return This . DeleteAllRowsAsync ( tableMapping , CancellationToken . None ) ;
141169 }
142170 }
0 commit comments