-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
RemovingDuplicatesAndOrderingResults.cs
51 lines (49 loc) · 2 KB
/
RemovingDuplicatesAndOrderingResults.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Linq;
using EFCorePgExercises.DataLayer;
using FluentAssertions;
using EFCorePgExercises.Utils;
namespace EFCorePgExercises.Exercises.SimpleSQLQueries
{
[FullyQualifiedTestClass]
public class RemovingDuplicatesAndOrderingResults
{
[FullyQualifiedTestMethod]
public void Test()
{
// https://pgexercises.com/questions/basic/unique.html
// How can you produce an ordered list of the first 10 surnames in the members table?
// The list must not contain duplicates.
// select distinct surname from cd.members order by surname limit 10;
EFServiceProvider.RunInContext(context =>
{
var members = context.Members.OrderBy(x => x.Surname)
.Select(x =>
new
{
x.Surname
})
.Distinct()
.Take(10)
.ToList();
/*
SELECT DISTINCT TOP(@__p_0) [m].[Surname]
FROM [Members] AS [m]
*/
var expectedResult = new[]
{
new { Surname = "Bader" } ,
new { Surname = "Baker" } ,
new { Surname = "Boothe" } ,
new { Surname = "Butters" } ,
new { Surname = "Coplin" } ,
new { Surname = "Crumpet" } ,
new { Surname = "Dare" } ,
new { Surname = "Farrell" } ,
new { Surname = "GUEST" } ,
new { Surname = "Genting" }
};
members.Should().BeEquivalentTo(expectedResult);
});
}
}
}