@@ -17,6 +17,14 @@ public class ModelWithSoftDelete : ISoftDelete
17
17
public bool IsDeleted { get ; set ; }
18
18
}
19
19
20
+ public class ModelWithSoftDeleteJoin : ISoftDelete
21
+ {
22
+ [ AutoIncrement ]
23
+ public int Id { get ; set ; }
24
+ public string Name { get ; set ; }
25
+ public bool IsDeleted { get ; set ; }
26
+ }
27
+
20
28
public static class SqlExpressionExtensions
21
29
{
22
30
public static SqlExpression < T > OnlyActive < T > ( this SqlExpression < T > q )
@@ -132,5 +140,39 @@ public void Can_add_generic_soft_delete_filter_to_SqlExpression_using_SqlExpress
132
140
OrmLiteConfig . SqlExpressionSelectFilter = null ;
133
141
}
134
142
}
143
+
144
+ [ Test ]
145
+ public void Can_use_interface_condition_on_table_with_join ( )
146
+ {
147
+ using ( var db = OpenDbConnection ( ) )
148
+ {
149
+ OrmLiteConfig . SqlExpressionSelectFilter = q =>
150
+ {
151
+ if ( q . ModelDef . ModelType . HasInterface ( typeof ( ISoftDelete ) ) )
152
+ {
153
+ q . Where < ISoftDelete > ( x => x . IsDeleted != true ) ;
154
+ }
155
+ } ;
156
+
157
+ db . DropAndCreateTable < ModelWithSoftDelete > ( ) ;
158
+ db . Insert ( new ModelWithSoftDelete { Name = "foo" } ) ;
159
+ db . Insert ( new ModelWithSoftDelete { Name = "bar" , IsDeleted = true } ) ;
160
+ db . DropAndCreateTable < ModelWithSoftDeleteJoin > ( ) ;
161
+ db . Insert ( new ModelWithSoftDeleteJoin { Name = "foo" } ) ;
162
+ db . Insert ( new ModelWithSoftDeleteJoin { Name = "bar" , IsDeleted = true } ) ;
163
+
164
+ var result = db . Single ( db . From < ModelWithSoftDelete > ( )
165
+ . Join < ModelWithSoftDeleteJoin > ( ( m , j ) => m . Name == j . Name )
166
+ . Where ( x => x . Name == "foo" ) ) ;
167
+ Assert . That ( result . Name , Is . EqualTo ( "foo" ) ) ;
168
+
169
+ result = db . Single ( db . From < ModelWithSoftDelete > ( )
170
+ . Join < ModelWithSoftDeleteJoin > ( ( m , j ) => m . Name == j . Name )
171
+ . Where ( x => x . Name == "bar" ) ) ;
172
+ Assert . That ( result , Is . Null ) ;
173
+
174
+ OrmLiteConfig . SqlExpressionSelectFilter = null ;
175
+ }
176
+ }
135
177
}
136
178
}
0 commit comments