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

Commit 3b86ff4

Browse files
committed
Add example of ColumnDistinct test with aliases
1 parent aed6215 commit 3b86ff4

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

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

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using NUnit.Framework;
1+
using System.Collections.Generic;
2+
using NUnit.Framework;
3+
using ServiceStack.DataAnnotations;
24
using ServiceStack.Text;
35

46
namespace ServiceStack.OrmLite.Tests.Issues
@@ -17,6 +19,19 @@ public class DistinctJoinColumn
1719
public string Name { get; set; }
1820
}
1921

22+
[Alias("t1")]
23+
class TableWithAliases
24+
{
25+
public int Id { get; set; }
26+
27+
[Alias("n1")]
28+
public string Name { get; set; }
29+
[Alias("n2")]
30+
public string Name1 { get; set; }
31+
[Alias("n3")]
32+
public string Name2 { get; set; }
33+
}
34+
2035
[TestFixture]
2136
public class SelectDistinctTests
2237
: OrmLiteTestBase
@@ -43,12 +58,38 @@ public void Can_Select_Multiple_Distinct_Columns()
4358
var q = db.From<DistinctColumn>()
4459
.Join<DistinctJoinColumn>()
4560
.SelectDistinct(dt => new { dt.Bar, dt.Foo });
46-
61+
4762
var result = db.Select(q);
4863
db.GetLastSql().Print();
4964

5065
Assert.That(result.Count, Is.EqualTo(2));
5166
}
5267
}
68+
69+
[Test]
70+
public void Does_select_alias_in_custom_select()
71+
{
72+
using (var db = OpenDbConnection())
73+
{
74+
db.DropAndCreateTable<TableWithAliases>();
75+
76+
for (var i = 1; i <= 5; i++)
77+
{
78+
db.Insert(new TableWithAliases { Id = i, Name = "foo" + i, Name1 = "bar" + i, Name2 = "qux" + i });
79+
}
80+
81+
var uniqueTrackNames = db.ColumnDistinct<string>(
82+
db.From<TableWithAliases>().Select(x => x.Name));
83+
84+
Assert.That(uniqueTrackNames, Is.EquivalentTo(new []
85+
{
86+
"foo1",
87+
"foo2",
88+
"foo3",
89+
"foo4",
90+
"foo5",
91+
}));
92+
}
93+
}
5394
}
5495
}

0 commit comments

Comments
 (0)