1
1
using System ;
2
+ using System . Data ;
3
+ using System . Linq ;
2
4
using NUnit . Framework ;
3
5
using ServiceStack . DataAnnotations ;
4
6
using ServiceStack . Logging ;
@@ -104,5 +106,62 @@ public void Can_reference_variable_in_sub_expression()
104
106
Assert . That ( expr . ToSelectStatement ( ) . NormalizeSql ( ) , Is . StringContaining ( "@0" ) ) ;
105
107
}
106
108
}
109
+
110
+ public class AnyObjectClass
111
+ {
112
+ public Guid ? Identity { get ; set ; }
113
+
114
+ public string Name { get ; set ; }
115
+
116
+ public IDbConnection db ;
117
+
118
+ [ DataAnnotations . Ignore ]
119
+ public decimal CustomProperty
120
+ {
121
+ get
122
+ {
123
+ return db . Select < AnyObjectClassItem >
124
+ ( s => Sql . In ( s . Identity ,
125
+ db . From < AnyObjectClassItem > ( )
126
+ . Where ( b => b . AnyObjectClassId == this . Identity )
127
+ . Select ( b => b . Identity ) )
128
+ ) . Sum ( r => r . PurchasePrice ) ;
129
+ }
130
+ }
131
+ }
132
+
133
+ public class AnyObjectClassItem
134
+ {
135
+ public Guid ? Identity { get ; set ; }
136
+
137
+ public string Name { get ; set ; }
138
+
139
+ public decimal PurchasePrice { get ; set ; }
140
+
141
+ [ ForeignKey ( typeof ( AnyObjectClass ) ) ]
142
+ public Guid AnyObjectClassId { get ; set ; }
143
+
144
+ public AnyObjectClass AnyObjectClass { get ; set ; }
145
+ }
146
+
147
+ [ Test ]
148
+ public void Can_select_sub_expression_when_called_within_a_datamodel ( )
149
+ {
150
+ using ( var db = OpenDbConnection ( ) )
151
+ {
152
+ db . DropTable < AnyObjectClassItem > ( ) ;
153
+ db . DropTable < AnyObjectClass > ( ) ;
154
+ db . CreateTable < AnyObjectClass > ( ) ;
155
+ db . CreateTable < AnyObjectClassItem > ( ) ;
156
+
157
+ var model = new AnyObjectClass { db = db } ;
158
+ var result = model . CustomProperty ;
159
+
160
+ db . GetLastSql ( ) . Print ( ) ;
161
+
162
+ result . PrintDump ( ) ;
163
+ }
164
+ }
165
+
107
166
}
108
167
}
0 commit comments