@@ -21,11 +21,24 @@ public SqlExpression<T> Join<Target>(Expression<Func<T, Target, bool>> joinExpr
21
21
return InternalJoin ( "INNER JOIN" , joinExpr ) ;
22
22
}
23
23
24
+ public SqlExpression < T > Join < Target > ( Expression < Func < T , Target , bool > > joinExpr , string joinFormat )
25
+ {
26
+ if ( joinFormat == null )
27
+ throw new ArgumentNullException ( "joinFormat" ) ;
28
+
29
+ return InternalJoin ( "INNER JOIN" , joinExpr , joinFormat ) ;
30
+ }
31
+
24
32
public SqlExpression < T > Join < Source , Target > ( Expression < Func < Source , Target , bool > > joinExpr = null )
25
33
{
26
34
return InternalJoin ( "INNER JOIN" , joinExpr ) ;
27
35
}
28
36
37
+ public SqlExpression < T > Join < Source , Target > ( Expression < Func < Source , Target , bool > > joinExpr , string joinFormat )
38
+ {
39
+ return InternalJoin ( "INNER JOIN" , joinExpr , joinFormat ) ;
40
+ }
41
+
29
42
public SqlExpression < T > Join ( Type sourceType , Type targetType , Expression joinExpr = null )
30
43
{
31
44
return InternalJoin ( "INNER JOIN" , joinExpr , sourceType . GetModelDefinition ( ) , targetType . GetModelDefinition ( ) ) ;
@@ -36,11 +49,24 @@ public SqlExpression<T> LeftJoin<Target>(Expression<Func<T, Target, bool>> joinE
36
49
return InternalJoin ( "LEFT JOIN" , joinExpr ) ;
37
50
}
38
51
52
+ public SqlExpression < T > LeftJoin < Target > ( Expression < Func < T , Target , bool > > joinExpr , string joinFormat )
53
+ {
54
+ if ( joinFormat == null )
55
+ throw new ArgumentNullException ( "joinFormat" ) ;
56
+
57
+ return InternalJoin ( "LEFT JOIN" , joinExpr , joinFormat ) ;
58
+ }
59
+
39
60
public SqlExpression < T > LeftJoin < Source , Target > ( Expression < Func < Source , Target , bool > > joinExpr = null )
40
61
{
41
62
return InternalJoin ( "LEFT JOIN" , joinExpr ) ;
42
63
}
43
64
65
+ public SqlExpression < T > LeftJoin < Source , Target > ( Expression < Func < Source , Target , bool > > joinExpr , string joinFormat )
66
+ {
67
+ return InternalJoin ( "LEFT JOIN" , joinExpr , joinFormat ) ;
68
+ }
69
+
44
70
public SqlExpression < T > LeftJoin ( Type sourceType , Type targetType , Expression joinExpr = null )
45
71
{
46
72
return InternalJoin ( "LEFT JOIN" , joinExpr , sourceType . GetModelDefinition ( ) , targetType . GetModelDefinition ( ) ) ;
@@ -51,11 +77,24 @@ public SqlExpression<T> RightJoin<Target>(Expression<Func<T, Target, bool>> join
51
77
return InternalJoin ( "RIGHT JOIN" , joinExpr ) ;
52
78
}
53
79
80
+ public SqlExpression < T > RightJoin < Target > ( Expression < Func < T , Target , bool > > joinExpr , string joinFormat )
81
+ {
82
+ if ( joinFormat == null )
83
+ throw new ArgumentNullException ( "joinFormat" ) ;
84
+
85
+ return InternalJoin ( "RIGHT JOIN" , joinExpr , joinFormat ) ;
86
+ }
87
+
54
88
public SqlExpression < T > RightJoin < Source , Target > ( Expression < Func < Source , Target , bool > > joinExpr = null )
55
89
{
56
90
return InternalJoin ( "RIGHT JOIN" , joinExpr ) ;
57
91
}
58
92
93
+ public SqlExpression < T > RightJoin < Source , Target > ( Expression < Func < Source , Target , bool > > joinExpr , string joinFormat )
94
+ {
95
+ return InternalJoin ( "RIGHT JOIN" , joinExpr , joinFormat ) ;
96
+ }
97
+
59
98
public SqlExpression < T > FullJoin < Target > ( Expression < Func < T , Target , bool > > joinExpr = null )
60
99
{
61
100
return InternalJoin ( "FULL JOIN" , joinExpr ) ;
@@ -76,12 +115,12 @@ public SqlExpression<T> CrossJoin<Source, Target>(Expression<Func<Source, Target
76
115
return InternalJoin ( "CROSS JOIN" , joinExpr ) ;
77
116
}
78
117
79
- protected SqlExpression < T > InternalJoin < Source , Target > ( string joinType , Expression < Func < Source , Target , bool > > joinExpr , string customJoinModifier = null )
118
+ protected SqlExpression < T > InternalJoin < Source , Target > ( string joinType , Expression < Func < Source , Target , bool > > joinExpr , string joinFormat = null )
80
119
{
81
120
var sourceDef = typeof ( Source ) . GetModelDefinition ( ) ;
82
121
var targetDef = typeof ( Target ) . GetModelDefinition ( ) ;
83
122
84
- return InternalJoin ( joinType , joinExpr , sourceDef , targetDef , customJoinModifier ) ;
123
+ return InternalJoin ( joinType , joinExpr , sourceDef , targetDef , joinFormat ) ;
85
124
}
86
125
87
126
private string InternalCreateSqlFromExpression ( Expression joinExpr , bool isCrossJoin )
@@ -125,7 +164,7 @@ public SqlExpression<T> CustomJoin(string joinString)
125
164
return this ;
126
165
}
127
166
128
- private SqlExpression < T > InternalJoin ( string joinType , Expression joinExpr , ModelDefinition sourceDef , ModelDefinition targetDef , string customJoinModifier = null )
167
+ private SqlExpression < T > InternalJoin ( string joinType , Expression joinExpr , ModelDefinition sourceDef , ModelDefinition targetDef , string joinFormat = null )
129
168
{
130
169
PrefixFieldWithTableName = true ;
131
170
@@ -145,17 +184,12 @@ private SqlExpression<T> InternalJoin(string joinType, Expression joinExpr, Mode
145
184
: InternalCreateSqlFromDefinitions ( sourceDef , targetDef , isCrossJoin ) ;
146
185
147
186
var joinDef = tableDefs . Contains ( targetDef ) && ! tableDefs . Contains ( sourceDef )
148
- ? sourceDef
149
- : targetDef ;
187
+ ? sourceDef
188
+ : targetDef ;
150
189
151
- if ( customJoinModifier != null )
152
- {
153
- FromExpression += " {0} {1} {2} {3}" . Fmt ( joinType , SqlTable ( joinDef ) , customJoinModifier , sqlExpr ) ;
154
- }
155
- else
156
- {
157
- FromExpression += " {0} {1} {2}" . Fmt ( joinType , SqlTable ( joinDef ) , sqlExpr ) ;
158
- }
190
+ FromExpression += joinFormat != null
191
+ ? " {0} {1}" . Fmt ( joinType , string . Format ( joinFormat , SqlTable ( joinDef ) , sqlExpr ) )
192
+ : " {0} {1} {2}" . Fmt ( joinType , SqlTable ( joinDef ) , sqlExpr ) ;
159
193
160
194
return this ;
161
195
}
0 commit comments