Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 3148617

Browse files
committed
Simplify JOIN aliases even further
1 parent 2b5b783 commit 3148617

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

src/ServiceStack.OrmLite.SqlServer/SqlServerTableHint.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
{
33
public class SqlServerTableHint
44
{
5-
public static JoinFormatDelegate ReadUncommitted = (table, expr) => "{0} WITH (READUNCOMMITTED) {1}".Fmt(table, expr);
6-
public static JoinFormatDelegate ReadCommitted = (table, expr) => "{0} WITH (READCOMMITTED) {1}".Fmt(table, expr);
7-
public static JoinFormatDelegate ReadPast = (table, expr) => "{0} WITH (READPAST) {1}".Fmt(table, expr);
8-
public static JoinFormatDelegate Serializable = (table, expr) => "{0} WITH (SERIALIZABLE) {1}".Fmt(table, expr);
9-
public static JoinFormatDelegate RepeatableRead = (table, expr) => "{0} WITH (REPEATABLEREAD) {1}".Fmt(table, expr);
5+
public static JoinFormatDelegate ReadUncommitted = (dialect, tableDef, expr) => "{0} WITH (READUNCOMMITTED) {1}".Fmt(dialect.GetQuotedTableName(tableDef), expr);
6+
public static JoinFormatDelegate ReadCommitted = (dialect, tableDef, expr) => "{0} WITH (READCOMMITTED) {1}".Fmt(dialect.GetQuotedTableName(tableDef), expr);
7+
public static JoinFormatDelegate ReadPast = (dialect, tableDef, expr) => "{0} WITH (READPAST) {1}".Fmt(dialect.GetQuotedTableName(tableDef), expr);
8+
public static JoinFormatDelegate Serializable = (dialect, tableDef, expr) => "{0} WITH (SERIALIZABLE) {1}".Fmt(dialect.GetQuotedTableName(tableDef), expr);
9+
public static JoinFormatDelegate RepeatableRead = (dialect, tableDef, expr) => "{0} WITH (REPEATABLEREAD) {1}".Fmt(dialect.GetQuotedTableName(tableDef), expr);
1010
}
1111
}

src/ServiceStack.OrmLite/Expressions/SqlExpression.Join.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace ServiceStack.OrmLite
99
{
10+
public delegate string JoinFormatDelegate(IOrmLiteDialectProvider dialect, ModelDefinition tableDef, string joinExpr);
11+
1012
public abstract partial class SqlExpression<T> : ISqlExpression
1113
{
1214
protected List<ModelDefinition> tableDefs = new List<ModelDefinition>();
@@ -188,7 +190,7 @@ private SqlExpression<T> InternalJoin(string joinType, Expression joinExpr, Mode
188190
: targetDef;
189191

190192
FromExpression += joinFormat != null
191-
? " {0} {1}".Fmt(joinType, joinFormat(SqlTable(joinDef), sqlExpr))
193+
? " {0} {1}".Fmt(joinType, joinFormat(DialectProvider, joinDef, sqlExpr))
192194
: " {0} {1} {2}".Fmt(joinType, SqlTable(joinDef), sqlExpr);
193195

194196
return this;

src/ServiceStack.OrmLite/Expressions/SqlExpression.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,8 +2235,6 @@ public interface ISqlExpression
22352235
string SelectInto<TModel>();
22362236
}
22372237

2238-
public delegate string JoinFormatDelegate(string table, string joinExpr);
2239-
22402238
public class PartialSqlString
22412239
{
22422240
public PartialSqlString(string text)

src/ServiceStack.OrmLite/OrmLiteReadExpressionsApi.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ public static SqlExpression<T> From<T>(this IDbConnection dbConn, string fromExp
7070
return expr;
7171
}
7272

73-
public static JoinFormatDelegate JoinAlias<T>(this IDbConnection dbConn, string alias)
73+
public static JoinFormatDelegate JoinAlias(this IDbConnection dbConn, string alias)
7474
{
75-
var dialectProvider = dbConn.GetDialectProvider();
76-
var modelDef = typeof(T).GetModelDefinition();
77-
return (table, expr) => "{0} {1} {2}".Fmt(table, alias,
78-
expr.Replace(dialectProvider.GetQuotedTableName(modelDef), dialectProvider.GetQuotedTableName(alias)));
75+
return (dialect, tableDef, expr) => string.Format("{0} {1} {2}",
76+
dialect.GetQuotedTableName(tableDef),
77+
alias,
78+
expr.Replace(dialect.GetQuotedTableName(tableDef), dialect.GetQuotedTableName(alias)));
7979
}
8080

8181
/// <summary>

tests/ServiceStack.OrmLite.Tests/Issues/MultipleSelfJoinsWithAliases.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ public void Can_use_cusom_SqlExpression_to_add_multiple_self_Left_Joins()
107107

108108
//Alternative
109109
q = db.From<Sale>()
110-
.LeftJoin<ContactIssue>((s,c) => s.SellerId == c.Id, db.JoinAlias<ContactIssue>("seller"))
111-
.LeftJoin<ContactIssue>((s,c) => s.BuyerId == c.Id, db.JoinAlias<ContactIssue>("buyer"))
110+
.LeftJoin<ContactIssue>((s,c) => s.SellerId == c.Id, db.JoinAlias("seller"))
111+
.LeftJoin<ContactIssue>((s,c) => s.BuyerId == c.Id, db.JoinAlias("buyer"))
112112
.Select<Sale, ContactIssue>((s,c) => new {
113113
sale = Sql.AllFields(s),
114114
BuyerFirstName = Sql.JoinAlias(c.FirstName, "buyer"),

0 commit comments

Comments
 (0)