Created
March 7, 2014 08:16
-
-
Save janv8000/9407469 to your computer and use it in GitHub Desktop.
Test case for http://stackoverflow.com/questions/6556077/distinct-in-linq-with-anonymous-types-in-vb-net
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<TestFixture()> | |
Public Class StackOverflowQuestion6556077Test | |
Private _originalList As Record() | |
Private Class Record | |
Public Country As String | |
Public CountryID As Integer | |
End Class | |
<SetUp> | |
Public Sub SetUp() | |
_originalList = {New Record With {.Country = "Spain", .CountryID = 1}, | |
New Record With {.Country = "Spain", .CountryID = 1}} | |
End Sub | |
<Test()> | |
Public Sub TestWithExplicitAnonymousType() | |
Dim query = From c In _originalList Select New With {.Country = c.Country, .CountryID = c.CountryID} | |
Assert.AreEqual(query.Distinct.Count(), 1) | |
End Sub | |
<Test()> | |
Public Sub TestWithAnonymousTypeFromQuery() | |
Dim query = From c In _originalList Select c.Country, c.CountryID 'No explicit New here! | |
Assert.AreEqual(query.Distinct.Count(), 1) | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment