comparison Source/Data/Sql/Join.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.Text;
4
5 namespace BLToolkit.Data.Sql
6 {
7 using Reflection.Extension;
8
9 public class Join : IQueryElement, ICloneableElement
10 {
11 public Join()
12 {
13 }
14
15 public Join(string tableName, params JoinOn[] joinOns)
16 : this(tableName, null, joinOns)
17 {
18 }
19
20 public Join(string tableName, string alias, params JoinOn[] joinOns)
21 {
22 _tableName = tableName;
23 _alias = alias;
24 _joinOns.AddRange(joinOns);
25 }
26
27 public Join(string tableName, string alias, IEnumerable<JoinOn> joinOns)
28 {
29 _tableName = tableName;
30 _alias = alias;
31 _joinOns.AddRange(joinOns);
32 }
33
34 public Join(AttributeExtension ext)
35 {
36 _tableName = (string)ext["TableName"];
37 _alias = (string)ext["Alias"];
38
39 var col = ext.Attributes["On"];
40
41 foreach (AttributeExtension ae in col)
42 _joinOns.Add(new JoinOn(ae));
43 }
44
45 private string _tableName;
46 public string TableName { get { return _tableName; } set { _tableName = value; } }
47
48 private string _alias;
49 public string Alias { get { return _alias; } set { _alias = value; } }
50
51 readonly List<JoinOn> _joinOns = new List<JoinOn>();
52 public List<JoinOn> JoinOns
53 {
54 get { return _joinOns; }
55 }
56
57 public Join Clone()
58 {
59 var join = new Join(_tableName, _alias);
60
61 foreach (var on in JoinOns)
62 join.JoinOns.Add(new JoinOn(on.Field, on.OtherField, on.Expression));
63
64 return join;
65 }
66
67 #region IQueryElement Members
68
69 public QueryElementType ElementType { get { return QueryElementType.Join; } }
70
71 StringBuilder IQueryElement.ToString(StringBuilder sb, Dictionary<IQueryElement,IQueryElement> dic)
72 {
73 return sb;
74 }
75
76 #endregion
77
78 #region ICloneableElement Members
79
80 public ICloneableElement Clone(Dictionary<ICloneableElement,ICloneableElement> objectTree, Predicate<ICloneableElement> doClone)
81 {
82 if (!doClone(this))
83 return this;
84
85 ICloneableElement clone;
86
87 if (!objectTree.TryGetValue(this, out clone))
88 objectTree.Add(this, clone = new Join(
89 _tableName,
90 _alias,
91 _joinOns.ConvertAll(j => (JoinOn)j.Clone(objectTree, doClone))));
92
93 return clone;
94 }
95
96 #endregion
97 }
98 }