1
- using NUnit . Framework ;
1
+ using System ;
2
+ using NUnit . Framework ;
2
3
using ServiceStack . DataAnnotations ;
4
+ using ServiceStack . Model ;
3
5
using ServiceStack . Text ;
4
6
5
7
namespace ServiceStack . OrmLite . Tests . Issues
@@ -75,16 +77,13 @@ public void Can_query_with_Schema_and_alias_attributes()
75
77
db . DropAndCreateTable < Page > ( ) ;
76
78
77
79
db . Save ( new Page {
78
- ReportSectionId = 1 ,
79
80
SectionId = 1 ,
80
81
} , references : true ) ;
81
82
db . Save ( new Page {
82
- ReportSectionId = 2 ,
83
83
SectionId = 2 ,
84
84
} , references : true ) ;
85
85
db . Save ( new Section {
86
86
Id = 1 ,
87
- ReportSectionId = 1 ,
88
87
Name = "Name1" ,
89
88
ReportId = 15 ,
90
89
} , references : true ) ;
@@ -102,34 +101,184 @@ public void Can_query_with_Schema_and_alias_attributes()
102
101
Assert . That ( results [ 0 ] . Name , Is . EqualTo ( "Name1" ) ) ;
103
102
}
104
103
}
104
+
105
+ [ Test ]
106
+ public void Does_complex_query_using_Schemas_with_LeftJoins ( )
107
+ {
108
+ using ( var db = OpenDbConnection ( ) )
109
+ {
110
+ db . DropAndCreateTable < Editable > ( ) ;
111
+ db . DropAndCreateTable < EditableRevision > ( ) ;
112
+ db . DropAndCreateTable < LogEntry > ( ) ;
113
+ db . DropAndCreateTable < Report > ( ) ;
114
+ db . DropAndCreateTable < Page > ( ) ;
115
+ db . DropAndCreateTable < Section > ( ) ;
116
+
117
+ var q = db . From < Section > ( )
118
+ . Join < Section , Page > ( ( s , p ) => s . Id == p . SectionId )
119
+ . Join < Page , Editable > ( ( p , e ) => p . Id == e . PageId )
120
+ . Where < Section , Page > ( ( s , p ) => s . ReportId == 15 && p . Index == 24 ) ;
121
+
122
+ var result = db . Select < Editable > ( q ) ;
123
+
124
+ db . GetLastSql ( ) . Print ( ) ;
125
+ }
126
+ }
127
+ }
128
+
129
+ [ Alias ( "Editables" ) ]
130
+ [ Schema ( "MicroSite" ) ]
131
+ public partial class Editable : IHasId < int >
132
+ {
133
+ public string Content { get ; set ; }
134
+
135
+ [ Alias ( "EditableID" ) ]
136
+ [ AutoIncrement ]
137
+ [ PrimaryKey ]
138
+ public int Id { get ; set ; }
139
+
140
+ [ Required ]
141
+ public int Index { get ; set ; }
142
+
143
+ [ Alias ( "ReportPageID" ) ]
144
+ [ Required ]
145
+ public int PageId { get ; set ; }
146
+
147
+ public string Styles { get ; set ; }
148
+
149
+ [ Alias ( "Type" ) ]
150
+ [ Required ]
151
+ public int TypeId { get ; set ; }
152
+ }
153
+
154
+ [ Alias ( "EditableRevisions" ) ]
155
+ [ Schema ( "MicroSite" ) ]
156
+ public partial class EditableRevision : IHasId < int >
157
+ {
158
+ public string Content { get ; set ; }
159
+
160
+ [ Required ]
161
+ public DateTime Date { get ; set ; }
162
+
163
+ [ Alias ( "EditableID" ) ]
164
+ [ Required ]
165
+ public int EditableId { get ; set ; }
166
+
167
+ [ Required ]
168
+ public int EmployeeId { get ; set ; }
169
+
170
+ [ Alias ( "EditableRevisionsID" ) ]
171
+ [ AutoIncrement ]
172
+ [ PrimaryKey ]
173
+ public int Id { get ; set ; }
174
+
175
+ public string Reason { get ; set ; }
176
+ public string Styles { get ; set ; }
105
177
}
106
178
107
- [ Schema ( "Schema ") ]
108
- [ Alias ( "PageAlias ") ]
109
- public class Page
179
+ [ Alias ( "LogEntries ") ]
180
+ [ Schema ( "MicroSite ") ]
181
+ public class LogEntry : IHasId < int >
110
182
{
183
+ [ Required ]
184
+ public DateTime Date { get ; set ; }
185
+
186
+ [ Alias ( "LogEntriesID" ) ]
111
187
[ AutoIncrement ]
188
+ [ PrimaryKey ]
112
189
public int Id { get ; set ; }
113
190
114
- [ Alias ( "ReportSectionIdAlias" ) ]
115
- public int ReportSectionId { get ; set ; }
191
+ [ Required ]
192
+ public int KlasId { get ; set ; }
193
+
194
+ [ Required ]
195
+ public int PageTrackerId { get ; set ; }
196
+
197
+ [ Alias ( "ReportID" ) ]
198
+ [ Required ]
199
+ public int ReportId { get ; set ; }
200
+
201
+ [ Alias ( "ReportPageID" ) ]
202
+ [ Required ]
203
+ public int PageId { get ; set ; }
204
+
205
+ public string RequestUrl { get ; set ; }
206
+
207
+ [ Alias ( "Type" ) ]
208
+ [ Required ]
209
+ public int TypeId { get ; set ; }
210
+ }
211
+
212
+ [ Alias ( "ReportPages" ) ]
213
+ [ Schema ( "MicroSite" ) ]
214
+ public partial class Page : IHasId < int >
215
+ {
216
+ [ Required ]
217
+ public int AccessLevel { get ; set ; }
218
+
219
+ [ Required ]
220
+ public int AssignedEmployeeId { get ; set ; }
221
+
222
+ [ Required ]
223
+ public bool Cover { get ; set ; }
224
+
225
+ [ Required ]
226
+ public bool Deleted { get ; set ; }
227
+
228
+ [ Required ]
229
+ public bool Disabled { get ; set ; }
230
+
231
+ [ Alias ( "ReportPageID" ) ]
232
+ [ AutoIncrement ]
233
+ [ PrimaryKey ]
234
+ public int Id { get ; set ; }
116
235
117
- [ Alias ( "SectionIdAlias" ) ]
236
+ [ Required ]
237
+ public int Index { get ; set ; }
238
+
239
+ public string Name { get ; set ; }
240
+
241
+ [ Alias ( "ReportSectionID" ) ]
242
+ [ Required ]
118
243
public int SectionId { get ; set ; }
244
+
245
+ public string Template { get ; set ; }
119
246
}
120
247
121
- [ Schema ( "Schema ") ]
122
- [ Alias ( "SectionAlias ") ]
123
- public class Section
248
+ [ Alias ( "Reports ") ]
249
+ [ Schema ( "MicroSite ") ]
250
+ public partial class Report : IHasId < int >
124
251
{
252
+ [ Required ]
253
+ public int DefaultAccessLevel { get ; set ; }
254
+
255
+ [ Required ]
256
+ public bool Deleted { get ; set ; }
257
+
258
+ public string Description { get ; set ; }
259
+
260
+ [ Alias ( "ReportID" ) ]
261
+ [ AutoIncrement ]
262
+ [ PrimaryKey ]
125
263
public int Id { get ; set ; }
126
264
127
- [ Alias ( "ReportSectionIdAlias" ) ]
128
- public int ReportSectionId { get ; set ; }
265
+ public string Name { get ; set ; }
266
+ }
267
+
268
+ [ Alias ( "ReportSections" ) ]
269
+ [ Schema ( "MicroSite" ) ]
270
+ public class Section : IHasId < int >
271
+ {
272
+ [ Alias ( "ReportSectionID" ) ]
273
+ [ AutoIncrement ]
274
+ [ PrimaryKey ]
275
+ public int Id { get ; set ; }
129
276
130
- [ Alias ( "NameAlias" ) ]
131
277
public string Name { get ; set ; }
132
- [ Alias ( "ReportIdAlias" ) ]
278
+
279
+ [ Alias ( "ReportID" ) ]
280
+ [ Required ]
133
281
public int ReportId { get ; set ; }
134
282
}
283
+
135
284
}
0 commit comments