comparison UnitTests/Linq/ConcatUnionTest.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Linq;
3
4 using BLToolkit.Data.DataProvider;
5 using BLToolkit.Data.Linq;
6 using BLToolkit.DataAccess;
7
8 using NUnit.Framework;
9
10 namespace Data.Linq
11 {
12 using Model;
13
14 [TestFixture]
15 public class ConcatUnionTest : TestBase
16 {
17 [Test]
18 public void Concat1()
19 {
20 var expected =
21 (from p in Parent where p.ParentID == 1 select p).Concat(
22 (from p in Parent where p.ParentID == 2 select p));
23
24 ForEachProvider(db => AreEqual(expected,
25 (from p in db.Parent where p.ParentID == 1 select p).Concat(
26 (from p in db.Parent where p.ParentID == 2 select p))));
27 }
28
29 [Test]
30 public void Concat11()
31 {
32 ForEachProvider(db => AreEqual(
33 (from ch in Child where ch.ParentID == 1 select ch.Parent).Concat(
34 (from ch in Child where ch.ParentID == 2 select ch.Parent)),
35 (from ch in db.Child where ch.ParentID == 1 select ch.Parent).Concat(
36 (from ch in db.Child where ch.ParentID == 2 select ch.Parent))));
37 }
38
39 [Test]
40 public void Concat12()
41 {
42 ForEachProvider(db => AreEqual(
43 (from p in Parent where p.ParentID == 1 select p).Concat(
44 (from ch in Child where ch.ParentID == 2 select ch.Parent)),
45 (from p in db.Parent where p.ParentID == 1 select p).Concat(
46 (from ch in db.Child where ch.ParentID == 2 select ch.Parent))));
47 }
48
49 [Test]
50 public void Concat2()
51 {
52 var expected =
53 (from p in Parent where p.ParentID == 1 select p).Concat(
54 (from p in Parent where p.ParentID == 2 select p)).Concat(
55 (from p in Parent where p.ParentID == 4 select p));
56
57 ForEachProvider(db => AreEqual(expected,
58 (from p in db.Parent where p.ParentID == 1 select p).Concat(
59 (from p in db.Parent where p.ParentID == 2 select p)).Concat(
60 (from p in db.Parent where p.ParentID == 4 select p))));
61 }
62
63 [Test]
64 public void Concat3()
65 {
66 var expected =
67 (from p in Parent where p.ParentID == 1 select p).Concat(
68 (from p in Parent where p.ParentID == 2 select p).Concat(
69 (from p in Parent where p.ParentID == 4 select p)));
70
71 ForEachProvider(db => AreEqual(expected,
72 (from p in db.Parent where p.ParentID == 1 select p).Concat(
73 (from p in db.Parent where p.ParentID == 2 select p).Concat(
74 (from p in db.Parent where p.ParentID == 4 select p)))));
75 }
76
77 [Test]
78 public void Concat4()
79 {
80 var expected =
81 (from c in Child where c.ParentID == 1 select c).Concat(
82 (from c in Child where c.ParentID == 3 select new Child { ParentID = c.ParentID, ChildID = c.ChildID + 1000 }).
83 Where(c => c.ChildID != 1032));
84
85 ForEachProvider(db => AreEqual(expected,
86 (from c in db.Child where c.ParentID == 1 select c).Concat(
87 (from c in db.Child where c.ParentID == 3 select new Child { ParentID = c.ParentID, ChildID = c.ChildID + 1000 })).
88 Where(c => c.ChildID != 1032)));
89 }
90
91 [Test]
92 public void Concat401()
93 {
94 var expected =
95 (from c in Child where c.ParentID == 1 select c).Concat(
96 (from c in Child where c.ParentID == 3 select new Child { ChildID = c.ChildID + 1000, ParentID = c.ParentID }).
97 Where(c => c.ChildID != 1032));
98
99 ForEachProvider(db => AreEqual(expected,
100 (from c in db.Child where c.ParentID == 1 select c).Concat(
101 (from c in db.Child where c.ParentID == 3 select new Child { ChildID = c.ChildID + 1000, ParentID = c.ParentID })).
102 Where(c => c.ChildID != 1032)));
103 }
104
105 [Test]
106 public void Concat5()
107 {
108 ForEachProvider(
109 new[] { ProviderName.DB2, ProviderName.Informix },
110 db => AreEqual(
111 (from c in Child where c.ParentID == 1 select c).Concat(
112 (from c in Child where c.ParentID == 3 select new Child { ChildID = c.ChildID + 1000 }).
113 Where(c => c.ChildID != 1032)),
114 (from c in db.Child where c.ParentID == 1 select c).Concat(
115 (from c in db.Child where c.ParentID == 3 select new Child { ChildID = c.ChildID + 1000 })).
116 Where(c => c.ChildID != 1032)));
117 }
118
119 [Test]
120 public void Concat501()
121 {
122 ForEachProvider(new[] { ProviderName.DB2, ProviderName.Informix },
123 db => AreEqual(
124 (from c in Child where c.ParentID == 1 select new Child { ParentID = c.ParentID }).Concat(
125 (from c in Child where c.ParentID == 3 select new Child { ChildID = c.ChildID + 1000 }).
126 Where(c => c.ParentID == 1)),
127 (from c in db.Child where c.ParentID == 1 select new Child { ParentID = c.ParentID }).Concat(
128 (from c in db.Child where c.ParentID == 3 select new Child { ChildID = c.ChildID + 1000 })).
129 Where(c => c.ParentID == 1)));
130 }
131
132 [Test]
133 public void Concat502()
134 {
135 ForEachProvider(new[] { ProviderName.DB2, ProviderName.Informix },
136 db => AreEqual(
137 (from c in Child where c.ParentID == 1 select c.Parent).Concat(
138 (from c in Child where c.ParentID == 3 select c.Parent).
139 Where(p => p.Value1.Value != 2)),
140 (from c in db.Child where c.ParentID == 1 select c.Parent).Concat(
141 (from c in db.Child where c.ParentID == 3 select c.Parent)).
142 Where(p => p.Value1.Value != 2)));
143 }
144
145 [Test]
146 public void Concat6()
147 {
148 ForEachProvider(new[] { ProviderName.SqlCe },
149 db => AreEqual(
150 Child.Where(c => c.GrandChildren.Count == 2).Concat( Child.Where(c => c.GrandChildren.Count() == 3)),
151 db.Child.Where(c => c.GrandChildren.Count == 2).Concat(db.Child.Where(c => c.GrandChildren.Count() == 3))));
152 }
153
154 [Test]
155 public void Concat7([IncludeDataContexts("Northwind")] string context)
156 {
157 using (var db = new NorthwindDB())
158 AreEqual(
159 Customer.Where(c => c.Orders.Count <= 1).Concat( Customer.Where(c => c.Orders.Count > 1)),
160 db.Customer.Where(c => c.Orders.Count <= 1).Concat(db.Customer.Where(c => c.Orders.Count > 1)));
161 }
162
163 [Test]
164 public void Concat81()
165 {
166 ForEachProvider(
167 db => AreEqual(
168 Parent.Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID, }).Concat(
169 Child. Select(c => new { ID1 = c.ParentID, ID2 = c.ChildID, })),
170 db.Parent.Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID, }).Concat(
171 db.Child. Select(c => new { ID1 = c.ParentID, ID2 = c.ChildID, }))));
172 }
173
174 [Test]
175 public void Concat82()
176 {
177 ForEachProvider(
178 db => AreEqual(
179 Child. Select(c => new { ID1 = c.ParentID, ID2 = c.ChildID, }).Concat(
180 Parent.Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID, })),
181 db.Child. Select(c => new { ID1 = c.ParentID, ID2 = c.ChildID, }).Concat(
182 db.Parent.Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID, }))));
183 }
184
185 [Test]
186 public void Concat83()
187 {
188 ForEachProvider(
189 db => AreEqual(
190 Parent.Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID, ID3 = c.Value1 ?? 0, }).Concat(
191 Child. Select(c => new { ID1 = c.ParentID, ID2 = c.ChildID, ID3 = c.ParentID + 1, })),
192 db.Parent.Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID, ID3 = c.Value1 ?? 0, }).Concat(
193 db.Child. Select(c => new { ID1 = c.ParentID, ID2 = c.ChildID, ID3 = c.ParentID + 1, }))));
194 }
195
196 [Test]
197 public void Concat84()
198 {
199 ForEachProvider(
200 db => AreEqual(
201 Child. Select(c => new { ID1 = c.ParentID, ID2 = c.ChildID, ID3 = c.ParentID + 1, }).Concat(
202 Parent.Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID, ID3 = c.Value1 ?? 0, })),
203 db.Child. Select(c => new { ID1 = c.ParentID, ID2 = c.ChildID, ID3 = c.ParentID + 1, }).Concat(
204 db.Parent.Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID, ID3 = c.Value1 ?? 0, }))));
205 }
206
207 [Test]
208 public void Concat85()
209 {
210 ForEachProvider(
211 db => AreEqual(
212 Parent.Select(c => new { ID1 = c.ParentID, ID2 = c.Value1 ?? 0, ID3 = c.ParentID, }).Concat(
213 Child. Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID + 1, ID3 = c.ChildID, })),
214 db.Parent.Select(c => new { ID1 = c.ParentID, ID2 = c.Value1 ?? 0, ID3 = c.ParentID, }).Concat(
215 db.Child. Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID + 1, ID3 = c.ChildID, }))));
216 }
217
218 [Test]
219 public void Concat851()
220 {
221 ForEachProvider(
222 db => AreEqual(
223 Parent.Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID, ID3 = c.ParentID, }).Concat(
224 Child. Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID + 1, ID3 = c.ChildID, })),
225 db.Parent.Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID, ID3 = c.ParentID, }).Concat(
226 db.Child. Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID + 1, ID3 = c.ChildID, }))));
227 }
228
229 [Test]
230 public void Concat86()
231 {
232 ForEachProvider(
233 db => AreEqual(
234 Child. Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID + 1, ID3 = c.ChildID, }).Concat(
235 Parent.Select(c => new { ID1 = c.ParentID, ID2 = c.Value1 ?? 0, ID3 = c.ParentID, })),
236 db.Child. Select(c => new { ID1 = c.ParentID, ID2 = c.ParentID + 1, ID3 = c.ChildID, }).Concat(
237 db.Parent.Select(c => new { ID1 = c.ParentID, ID2 = c.Value1 ?? 0, ID3 = c.ParentID, }))));
238 }
239
240 [Test]
241 public void Concat87()
242 {
243 ForEachProvider(
244 new[] { ProviderName.Informix },
245 db => AreEqual(
246 Child. Select(c => new Parent { ParentID = c.ParentID }).Concat(
247 Parent.Select(c => new Parent { Value1 = c.Value1 })),
248 db.Child. Select(c => new Parent { ParentID = c.ParentID }).Concat(
249 db.Parent.Select(c => new Parent { Value1 = c.Value1 }))));
250 }
251
252 [Test]
253 public void Concat871()
254 {
255 ForEachProvider(
256 new[] { ProviderName.Informix },
257 db => AreEqual(
258 Parent.Select(c => new Parent { Value1 = c.Value1 }).Concat(
259 Child. Select(c => new Parent { ParentID = c.ParentID })),
260 db.Parent.Select(c => new Parent { Value1 = c.Value1 }).Concat(
261 db.Child. Select(c => new Parent { ParentID = c.ParentID }))));
262 }
263
264 [Test]
265 public void Concat88()
266 {
267 ForEachProvider(
268 db => AreEqual(
269 Child. Select(c => new Parent { Value1 = c.ChildID, ParentID = c.ParentID }).Concat(
270 Parent.Select(c => new Parent { ParentID = c.ParentID, Value1 = c.Value1 })),
271 db.Child. Select(c => new Parent { Value1 = c.ChildID, ParentID = c.ParentID }).Concat(
272 db.Parent.Select(c => new Parent { ParentID = c.ParentID, Value1 = c.Value1 }))));
273 }
274
275 [Test]
276 public void Concat89()
277 {
278 ForEachProvider(
279 new[] { ProviderName.Informix },
280 db => AreEqual(
281 Child. Select(c => new Parent { Value1 = c.ParentID, ParentID = c.ParentID }).Concat(
282 Parent.Select(c => new Parent { ParentID = c.ParentID })),
283 db.Child. Select(c => new Parent { Value1 = c.ParentID, ParentID = c.ParentID }).Concat(
284 db.Parent.Select(c => new Parent { ParentID = c.ParentID }))));
285 }
286
287 [Test]
288 public void Union1()
289 {
290 ForEachProvider(db => AreEqual(
291 (from g in GrandChild join ch in Child on g.ChildID equals ch.ChildID select ch).Union(
292 (from ch in Child join p in Parent on ch.ParentID equals p.ParentID select ch)),
293 (from g in db.GrandChild join ch in db.Child on g.ChildID equals ch.ChildID select ch).Union(
294 (from ch in db.Child join p in db.Parent on ch.ParentID equals p.ParentID select ch))));
295 }
296
297 [Test]
298 public void Union2()
299 {
300 ForEachProvider(db => AreEqual(
301 from r in
302 (from g in GrandChild join ch in Child on g.ChildID equals ch.ChildID select ch.ChildID).Union(
303 (from ch in Child join p in Parent on ch.ParentID equals p.ParentID select ch.ChildID))
304 join child in Child on r equals child.ChildID
305 select child,
306 from r in
307 (from g in db.GrandChild join ch in db.Child on g.ChildID equals ch.ChildID select ch.ChildID).Union(
308 (from ch in db.Child join p in db.Parent on ch.ParentID equals p.ParentID select ch.ChildID))
309 join child in db.Child on r equals child.ChildID
310 select child));
311 }
312
313 [Test]
314 public void Union3()
315 {
316 ForEachProvider(db => AreEqual(
317 (from p in Parent select new { id = p.ParentID, val = true }).Union(
318 (from ch in Child select new { id = ch.ParentID, val = false })),
319 (from p in db.Parent select new { id = p.ParentID, val = true }).Union(
320 (from ch in db.Child select new { id = ch.ParentID, val = false }))));
321 }
322
323 [Test]
324 public void Union4()
325 {
326 ForEachProvider(db => AreEqual(
327 (from p in Parent select new { id = p.ParentID, val = true }).Union(
328 (from ch in Child select new { id = ch.ParentID, val = false }))
329 .Select(p => new { p.id, p.val }),
330 (from p in db.Parent select new { id = p.ParentID, val = true }).Union(
331 (from ch in db.Child select new { id = ch.ParentID, val = false }))
332 .Select(p => new { p.id, p.val })));
333 }
334
335 [Test]
336 public void Union41()
337 {
338 ForEachProvider(db => AreEqual(
339 (from p in Parent select new { id = p.ParentID, val = true }).Union(
340 (from ch in Child select new { id = ch.ParentID, val = false }))
341 .Select(p => p),
342 (from p in db.Parent select new { id = p.ParentID, val = true }).Union(
343 (from ch in db.Child select new { id = ch.ParentID, val = false }))
344 .Select(p => p)));
345 }
346
347 [Test]
348 public void Union42()
349 {
350 ForEachProvider(db => AreEqual(
351 (from p in Parent select new { id = p. ParentID, val = true }).Union(
352 (from ch in Child select new { id = ch.ParentID, val = false }))
353 .Select(p => p.val),
354 (from p in db.Parent select new { id = p. ParentID, val = true }).Union(
355 (from ch in db.Child select new { id = ch.ParentID, val = false }))
356 .Select(p => p.val)));
357 }
358
359 [Test]
360 public void Union421()
361 {
362 ForEachProvider(db => AreEqual(
363 (from p in Parent select new { id = p. ParentID, val = true }).Union(
364 (from p in Parent select new { id = p. ParentID, val = false }).Union(
365 (from ch in Child select new { id = ch.ParentID, val = false })))
366 .Select(p => p.val),
367 (from p in db.Parent select new { id = p. ParentID, val = true }).Union(
368 (from p in db.Parent select new { id = p. ParentID, val = false }).Union(
369 (from ch in db.Child select new { id = ch.ParentID, val = false })))
370 .Select(p => p.val)));
371 }
372
373 [Test]
374 public void Union5()
375 {
376 ForEachProvider(
377 new[] { ProviderName.Informix },
378 db => AreEqual(
379 (from p1 in Parent select p1).Union(
380 (from p2 in Parent select new Parent { ParentID = p2.ParentID }))
381 .Select(p => new Parent { ParentID = p.ParentID, Value1 = p.Value1 }),
382 (from p1 in db.Parent select p1).Union(
383 (from p2 in db.Parent select new Parent { ParentID = p2.ParentID }))
384 .Select(p => new Parent { ParentID = p.ParentID, Value1 = p.Value1 })));
385 }
386
387 [Test]
388 public void Union51()
389 {
390 ForEachProvider(
391 new[] { ProviderName.Informix },
392 db => AreEqual(
393 (from p1 in Parent select p1).Union(
394 (from p2 in Parent select new Parent { ParentID = p2.ParentID })),
395 (from p1 in db.Parent select p1).Union(
396 (from p2 in db.Parent select new Parent { ParentID = p2.ParentID }))));
397 }
398
399 [Test]
400 public void Union52()
401 {
402 ForEachProvider(
403 new[] { ProviderName.Access, ProviderName.Informix },
404 db => AreEqual(
405 (from p1 in Parent select new Parent { ParentID = p1.ParentID }).Union(
406 (from p2 in Parent select p2)),
407 (from p1 in db.Parent select new Parent { ParentID = p1.ParentID }).Union(
408 (from p2 in db.Parent select p2))));
409 }
410
411 [Test]
412 public void Union521()
413 {
414 ForEachProvider(
415 new[] { ProviderName.Access, ProviderName.Informix },
416 db => AreEqual(
417 (from p1 in Parent select new Parent { ParentID = p1.ParentID }).Union(
418 (from p2 in Parent select p2))
419 .Select(p => p.Value1),
420 (from p1 in db.Parent select new Parent { ParentID = p1.ParentID }).Union(
421 (from p2 in db.Parent select p2))
422 .Select(p => p.Value1)));
423 }
424
425 [Test]
426 public void Union522()
427 {
428 ForEachProvider(
429 new[] { ProviderName.Access, ProviderName.Informix },
430 db => AreEqual(
431 (from p1 in Parent select new Parent { Value1 = p1.Value1 }).Union(
432 (from p2 in Parent select p2)),
433 (from p1 in db.Parent select new Parent { Value1 = p1.Value1 }).Union(
434 (from p2 in db.Parent select p2))));
435 }
436
437 [Test]
438 public void Union523()
439 {
440 ForEachProvider(
441 new[] { ProviderName.Access, ProviderName.Informix },
442 db => AreEqual(
443 (from p1 in Parent select new Parent { ParentID = p1.ParentID }).Union(
444 (from p2 in Parent select p2)),
445 (from p1 in db.Parent select new Parent { ParentID = p1.ParentID }).Union(
446 (from p2 in db.Parent select p2))));
447 }
448
449 [Test]
450 public void Union53()
451 {
452 ForEachProvider(
453 new[] { ProviderName.Access, ProviderName.Informix },
454 db => AreEqual(
455 (from p1 in Parent select new Parent { ParentID = p1.ParentID }).Union(
456 (from p2 in Parent select new Parent { Value1 = p2.Value1 })),
457 (from p1 in db.Parent select new Parent { ParentID = p1.ParentID }).Union(
458 (from p2 in db.Parent select new Parent { Value1 = p2.Value1 }))));
459 }
460
461 //[Test]
462 public void Union54()
463 {
464 ForEachProvider(
465 //new[] { ProviderName.Access, ProviderName.Informix },
466 db => AreEqual(
467 (from p1 in Parent select new { ParentID = p1.ParentID, p = p1, ch = (Child)null }).Union(
468 (from p2 in Parent select new { ParentID = p2.Value1 ?? 0, p = (Parent)null, ch = p2.Children.First() })),
469 (from p1 in db.Parent select new { ParentID = p1.ParentID, p = p1, ch = (Child)null }).Union(
470 (from p2 in db.Parent select new { ParentID = p2.Value1 ?? 0, p = (Parent)null, ch = p2.Children.First() }))));
471 }
472
473 //[Test]
474 public void Union541()
475 {
476 ForEachProvider(
477 //new[] { ProviderName.Access, ProviderName.Informix },
478 db => AreEqual(
479 (from p1 in Parent select new { ParentID = p1.ParentID, p = p1, ch = (Child)null }).Union(
480 (from p2 in Parent select new { ParentID = p2.Value1 ?? 0, p = (Parent)null, ch = p2.Children.First() }))
481 .Select(p => new { p.ParentID, p.p, p.ch }),
482 (from p1 in db.Parent select new { ParentID = p1.ParentID, p = p1, ch = (Child)null }).Union(
483 (from p2 in db.Parent select new { ParentID = p2.Value1 ?? 0, p = (Parent)null, ch = p2.Children.First() }))
484 .Select(p => new { p.ParentID, p.p, p.ch })));
485 }
486
487 [TableName("Parent")]
488 public abstract class AbstractParent
489 {
490 public abstract int ParentID { get; set; }
491 public abstract int? Value1 { get; set; }
492 }
493
494 [Test]
495 public void UnionAbstract1([DataContexts] string context)
496 {
497 using (var db = GetDataContext(context))
498 {
499 var list = db.GetTable<AbstractParent>().Union(db.GetTable<AbstractParent>()).ToList();
500 Assert.AreEqual(Parent.Count(), list.Count);
501 }
502 }
503
504 [Test]
505 public void ObjectUnion1([DataContexts] string context)
506 {
507 using (var db = GetDataContext(context))
508 AreEqual(
509 (from p1 in Parent where p1.ParentID > 3 select p1).Union(
510 (from p2 in Parent where p2.ParentID <= 3 select p2)),
511 (from p1 in db.Parent where p1.ParentID > 3 select p1).Union(
512 (from p2 in db.Parent where p2.ParentID <= 3 select p2)));
513 }
514
515 //////[Test]
516 public void ObjectUnion2([DataContexts] string context)
517 {
518 using (var db = GetDataContext(context))
519 AreEqual(
520 (from p1 in Parent where p1.ParentID > 3 select p1).Union(
521 (from p2 in Parent where p2.ParentID <= 3 select (Parent)null)),
522 (from p1 in db.Parent where p1.ParentID > 3 select p1).Union(
523 (from p2 in db.Parent where p2.ParentID <= 3 select (Parent)null)));
524 }
525
526 [Test]
527 public void ObjectUnion3([DataContexts] string context)
528 {
529 using (var db = GetDataContext(context))
530 AreEqual(
531 (from p1 in Parent where p1.ParentID > 3 select new { p = p1 }).Union(
532 (from p2 in Parent where p2.ParentID <= 3 select new { p = p2 })),
533 (from p1 in db.Parent where p1.ParentID > 3 select new { p = p1 }).Union(
534 (from p2 in db.Parent where p2.ParentID <= 3 select new { p = p2 })));
535 }
536
537 //////[Test]
538 public void ObjectUnion4([DataContexts] string context)
539 {
540 using (var db = GetDataContext(context))
541 AreEqual(
542 (from p1 in Parent where p1.ParentID > 3 select new { p = new { p = p1, p1.ParentID } }).Union(
543 (from p2 in Parent where p2.ParentID <= 3 select new { p = new { p = p2, p2.ParentID } })),
544 (from p1 in db.Parent where p1.ParentID > 3 select new { p = new { p = p1, p1.ParentID } }).Union(
545 (from p2 in db.Parent where p2.ParentID <= 3 select new { p = new { p = p2, p2.ParentID } })));
546 }
547
548 //////[Test]
549 public void ObjectUnion5([DataContexts] string context)
550 {
551 using (var db = GetDataContext(context))
552 AreEqual(
553 (from p1 in Parent where p1.ParentID > 3 select new { p = new { p = p1, ParentID = p1.ParentID + 1 } }).Union(
554 (from p2 in Parent where p2.ParentID <= 3 select new { p = new { p = p2, ParentID = p2.ParentID + 1 } })),
555 (from p1 in db.Parent where p1.ParentID > 3 select new { p = new { p = p1, ParentID = p1.ParentID + 1 } }).Union(
556 (from p2 in db.Parent where p2.ParentID <= 3 select new { p = new { p = p2, ParentID = p2.ParentID + 1 } })));
557 }
558
559 [Test]
560 public void ObjectUnion()
561 {
562 using (var db = new NorthwindDB())
563 {
564 var q1 =
565 from p in db.Product
566 join c in db.Category on p.CategoryID equals c.CategoryID into g
567 from c in g.DefaultIfEmpty()
568 select new
569 {
570 p,
571 c.CategoryName,
572 p.ProductName
573 };
574
575 var q2 =
576 from p in db.Product
577 join c in db.Category on p.CategoryID equals c.CategoryID into g
578 from c in g.DefaultIfEmpty()
579 select new
580 {
581 p,
582 c.CategoryName,
583 p.ProductName
584 };
585
586 var q = q1.Union(q2).Take(5);
587
588 foreach (var item in q)
589 {
590 Console.WriteLine(item);
591 }
592 }
593 }
594
595 public class TestEntity1 { public int Id; public string Field1; }
596 public class TestEntity2 { public int Id; public string Field1; }
597
598 [Test]
599 public void Concat90()
600 {
601 using(var context = new TestDbManager())
602 {
603 var join1 =
604 from t1 in context.GetTable<TestEntity1>()
605 join t2 in context.GetTable<TestEntity2>()
606 on t1.Id equals t2.Id
607 into tmp
608 from t2 in tmp.DefaultIfEmpty()
609 select new { t1, t2 };
610
611 var join1Sql = join1.ToString();
612 Assert.IsNotNull(join1Sql);
613
614 var join2 =
615 from t2 in context.GetTable<TestEntity2>()
616 join t1 in context.GetTable<TestEntity1>()
617 on t2.Id equals t1.Id
618 into tmp
619 from t1 in tmp.DefaultIfEmpty()
620 where t1 == null
621 select new { t1, t2 };
622
623 var join2Sql = join2.ToString();
624 Assert.IsNotNull(join2Sql);
625
626 var fullJoin = join1.Concat(join2);
627
628 var fullJoinSql = fullJoin.ToString(); // BLToolkit.Data.Linq.LinqException : Types in Concat are constructed incompatibly.
629 Assert.IsNotNull(fullJoinSql);
630 }
631 }
632 }
633 }