Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linq Unique list ?

Posted on 2016-09-15
3
Medium Priority
?
86 Views
Last Modified: 2016-09-16
I am trying to get a list of unique ISBN as such
   Dim ISBNs = From row In dt Select row.Field(Of String)("ISBN").Distinct
But it is returning all including duplicates. What am doing wrong?
0
Comment
Question by:Jess31
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 41800168
Try it like this.[code]Dim ISBNs = (From row In dt
Select row.Field(Of String)("ISBN"))ToList()..Distinct()[/code]
0
 
LVL 34

Accepted Solution

by:
it_saige earned 2000 total points
ID: 41800169
You want to surround your from statement in paranthesis; e.g. -
Dim ISBNs = (From row In dt Select row.Field(Of String)("ISBN")).Distinct()

Open in new window


Proof of concept -
Module Module1
	ReadOnly Paragraphs As New List(Of String) From { _
		"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?", _
		"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains." _
	}

	Sub Main()
		For Each paragraph As String In Paragraphs
			Dim words = paragraph.Split(" ")
			Dim distinctWords = (From word In words Select word).Distinct()
			Console.WriteLine("There are {0} total words in Paragraph {1} and {2} distinct words.", words.Count, Paragraphs.IndexOf(paragraph), distinctWords.Count)
		Next
		Console.ReadLine()
	End Sub
End Module

Open in new window


Produces the following output -Capture.JPG
-saige-
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 41800196
You can also make use of the morelinq library's DistinctBy method:

Dim ISBNs = dt.Rows.DistinctBy(Function (row) row.Field(Of String)("ISBN"))

Open in new window


You can install morelinq via NuGet.
0

Featured Post

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question