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

Commit 2766bad

Browse files
committed
Change SelectInto to project aliases to target field names to allow auto mapping of aliased columns
1 parent c7a6d6f commit 2766bad

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ public string SelectInto<TModel>()
166166
sbSelect.AppendFormat("{0}.{1}",
167167
SqlTable(tableDef),
168168
tableFieldDef.GetQuotedName(DialectProvider));
169+
170+
if (tableFieldDef.Alias != null)
171+
sbSelect.Append(" AS ").Append(fieldDef.Name);
172+
169173
break;
170174
}
171175
}

tests/ServiceStack.OrmLite.Tests/Expression/ComplexJoinTests.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,25 @@ internal class JoinResult
6363
[BelongTo(typeof(FooBar))]
6464
public int Id { get; set; }
6565

66-
[Alias("fkBazId")]
6766
[BelongTo(typeof(FooBarBaz))]
6867
public int FooBarBazId { get; set; }
6968

7069
[BelongTo(typeof(FooBarBaz))]
7170
public decimal Amount { get; set; }
7271

73-
[Alias("fkBarId")]
7472
[BelongTo(typeof(Bar))]
7573
public Guid BarId { get; set; }
7674

7775
[BelongTo(typeof(Bar))]
7876
public string BarName { get; set; }
7977

80-
[Alias("fkBazId")]
8178
[BelongTo(typeof(Baz))]
8279
public int BazId { get; set; }
8380

8481
[BelongTo(typeof(Baz))]
8582
public string BazName { get; set; }
8683
}
8784

88-
8985
[TestFixture]
9086
public class ComplexJoinTests : OrmLiteTestBase
9187
{
@@ -166,10 +162,10 @@ public void ComplexJoin_with_SqlExpression()
166162
.Join<Bar>((dp, p) => dp.BarId == p.Id)
167163
.Join<FooBarBaz>((dp, dpss) => dp.Id == dpss.FooBarId)
168164
.Join<FooBarBaz, Baz>((dpss, ss) => dpss.BazId == ss.Id);
169-
165+
170166
var results = db.Select<JoinResult>(q);
171167

172-
db.GetLastSql().Replace("INNER","\n INNER").Print();
168+
db.GetLastSql().Replace("INNER", "\n INNER").Print();
173169

174170
results.PrintDump();
175171

0 commit comments

Comments
 (0)