Mercurial > pub > bltoolkit
comparison Mono/Test/Program.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 Data.Linq; | |
6 | |
7 namespace Test | |
8 { | |
9 class Program | |
10 { | |
11 static void Main() | |
12 { | |
13 BLToolkit.Data.DbManager.AddDataProvider(typeof(BLToolkit.Data.DataProvider.MySqlDataProvider)); | |
14 | |
15 using (var db = new TestDbManager("MySql")) | |
16 { | |
17 var list = new GenericConcatQuery(db, new object[] { "A", 1 }).Query().ToList(); | |
18 | |
19 foreach (var i in list) | |
20 Console.WriteLine(i.ToString()); | |
21 } | |
22 } | |
23 } | |
24 | |
25 public abstract class GenericQueryBase | |
26 { | |
27 private readonly IdlPatientSource m_ds; | |
28 | |
29 protected GenericQueryBase(ITestDataContext ds) | |
30 { | |
31 m_ds = new IdlPatientSource(ds); | |
32 } | |
33 | |
34 #region Object sources | |
35 | |
36 protected IQueryable<IdlPerson> AllPersons | |
37 { | |
38 get { return m_ds.Persons(); } | |
39 } | |
40 | |
41 protected IQueryable<IdlPatient> AllPatients | |
42 { | |
43 get { return m_ds.Patients(); } | |
44 } | |
45 | |
46 protected IQueryable<IdlGrandChild> AllGrandChilds | |
47 { | |
48 get { return m_ds.GrandChilds(); } | |
49 } | |
50 | |
51 #endregion | |
52 | |
53 public abstract IEnumerable<object> Query(); | |
54 } | |
55 | |
56 public class GenericConcatQuery : GenericQueryBase | |
57 { | |
58 private System.String @p1; | |
59 private System.Int32 @p2; | |
60 | |
61 public GenericConcatQuery(ITestDataContext ds, object[] args) | |
62 : base(ds) | |
63 { | |
64 @p1 = (System.String)args[0]; | |
65 @p2 = (System.Int32)args[1]; | |
66 } | |
67 | |
68 public override IEnumerable<object> Query() | |
69 { | |
70 return (from y in AllPersons | |
71 select y.Name) | |
72 .Concat( | |
73 from x in AllPersons | |
74 from z in AllPatients | |
75 where (x.Name == @p1 || z.Id == new ObjectId { Value = @p2 }) | |
76 select x.Name | |
77 ); | |
78 } | |
79 } | |
80 | |
81 public struct ObjectId | |
82 { | |
83 public ObjectId(int value) | |
84 { | |
85 m_value = value; | |
86 } | |
87 | |
88 private int m_value; | |
89 | |
90 public int Value | |
91 { | |
92 get { return m_value; } | |
93 set { m_value = value; } | |
94 } | |
95 | |
96 public static implicit operator int(ObjectId val) | |
97 { | |
98 return val.m_value; | |
99 } | |
100 } | |
101 | |
102 public struct NullableObjectId | |
103 { | |
104 public NullableObjectId(int? value) | |
105 { | |
106 m_value = value; | |
107 } | |
108 | |
109 private int? m_value; | |
110 | |
111 public int? Value | |
112 { | |
113 get { return m_value; } | |
114 set { m_value = value; } | |
115 } | |
116 | |
117 public static implicit operator int?(NullableObjectId val) | |
118 { | |
119 return val.m_value; | |
120 } | |
121 } | |
122 | |
123 public class IdlPatient | |
124 { | |
125 public ObjectId Id { get; set; } | |
126 } | |
127 | |
128 public class IdlPerson | |
129 { | |
130 public ObjectId Id { get; set; } | |
131 public string Name { get; set; } | |
132 } | |
133 | |
134 public class IdlGrandChild | |
135 { | |
136 public ObjectId ParentID { get; set; } | |
137 public ObjectId ChildID { get; set; } | |
138 public ObjectId GrandChildID { get; set; } | |
139 } | |
140 | |
141 public class IdlPatientEx : IdlPatient | |
142 { | |
143 public IdlPerson Person { get; set; } | |
144 } | |
145 | |
146 public class IdlPatientSource | |
147 { | |
148 private readonly ITestDataContext m_dc; | |
149 | |
150 public IdlPatientSource(ITestDataContext dc) | |
151 { | |
152 m_dc = dc; | |
153 } | |
154 | |
155 public IQueryable<IdlGrandChild> GrandChilds() | |
156 { | |
157 return m_dc.GrandChild.Select(x => new IdlGrandChild | |
158 { | |
159 ChildID = new ObjectId {Value = x.ChildID.Value}, | |
160 GrandChildID = new ObjectId { Value = x.GrandChildID.Value }, | |
161 ParentID = new ObjectId { Value = x.ParentID.Value } | |
162 }); | |
163 } | |
164 | |
165 public IQueryable<IdlPatient> Patients() | |
166 { | |
167 return m_dc.Patient.Select(x => new IdlPatient { Id = new ObjectId { Value = x.PersonID }, }); | |
168 } | |
169 | |
170 public IQueryable<IdlPerson> Persons() | |
171 { | |
172 return | |
173 m_dc.Person.Select( | |
174 x => new IdlPerson { Id = new ObjectId { Value = x.ID }, Name = x.FirstName, }); | |
175 } | |
176 } | |
177 } |