comparison UnitTests/Linq/UserTests/MultiPartIdentifierTest.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.Collections.Generic;
3 using System.Linq;
4
5 using BLToolkit.Data.Linq;
6 using BLToolkit.DataAccess;
7 using BLToolkit.Mapping;
8
9 using NUnit.Framework;
10
11 // ReSharper disable ClassNeverInstantiated.Local
12
13 namespace Data.Linq.UserTests
14 {
15 [TestFixture]
16 public class MultiPartIdentifierTest : TestBase
17 {
18 class Table1
19 {
20 public long Field1;
21 public long Field2;
22 public int? Field3;
23
24 [Association(ThisKey = "Field2", OtherKey = "Field2", CanBeNull = false)]
25 public Table2 Table2Ref { get; set; }
26
27 [Association(ThisKey = "Field3", OtherKey = "Field3", CanBeNull = true)]
28 public Table4 Table4Ref { get; set; }
29 }
30
31 class Table2
32 {
33 public long Field2 { get; set; }
34 public int Field4 { get; set; }
35
36 [Association(ThisKey = "Field2", OtherKey = "Field2", CanBeNull = false)]
37 public List<Table1> Table1s { get; set; }
38
39 [Association(ThisKey="Field4", OtherKey="Field4", CanBeNull=false)]
40 public Table3 Table3Ref { get; set; }
41 }
42
43 class Table3
44 {
45 public int Field4;
46
47 [Association(ThisKey="Field4", OtherKey="Field4", CanBeNull=true)]
48 public List<Table2> Table2s { get; set; }
49 }
50
51 class Table4
52 {
53 public int Field3 { get; set; }
54 public int Field4 { get; set; }
55
56 [Association(ThisKey = "Field3", OtherKey = "Field3", CanBeNull = true)]
57 public List<Table1> Table1s { get; set; }
58
59 [Association(ThisKey="Field4", OtherKey="ProblematicalField", CanBeNull=false)]
60 public Table5 Table5Ref { get; set; }
61 }
62
63 class Table5
64 {
65 public int? Field5;
66 public int ProblematicalField;
67
68 [Association(ThisKey = "Field5", OtherKey = "ProblematicalField", CanBeNull = true)]
69 public Table5 Table5Ref { get; set; }
70
71 [Association(ThisKey = "ProblematicalField", OtherKey = "Field4", CanBeNull = true)]
72 public List<Table4> Table4s { get; set; }
73 }
74
75 [Test]
76 public void Test([IncludeDataContexts("Sql2008")] string context)
77 {
78 using (var db = GetDataContext(context))
79 {
80 var q =
81 from t1 in db.GetTable<Table5>()
82 from t2 in
83 (from t3 in t1.Table4s.SelectMany(x => x.Table1s)
84 from t4 in
85 from t5 in t3.Table4Ref.Table5Ref.Table5Ref.Table4s
86 from t6 in t5.Table1s
87 select t6
88 select t4.Field1)
89 from t7 in
90 (from t8 in t1.Table5Ref.Table4s.SelectMany(x => x.Table1s)
91 from t9 in
92 from t10 in t8.Table2Ref.Table3Ref.Table2s
93 from t11 in t10.Table1s
94 select t11
95 select t9.Field1)
96 where t2 == t7
97 select t7;
98
99 var sql = q.ToString();
100 var idx = sql.IndexOf(",");
101
102 Assert.That(idx, Is.EqualTo(-1));
103 }
104 }
105 }
106 }