LINQ to Compare Lists

I am needing to compare values in two lists which are different types. What I need to do is find out if the AttendeeID is in both lists. If it is in both lists then do nothing, however, if the AttendeeID is not in both lists then we need to add that information to another list. I was trying to use LINQ to do this, however, I'm not doing something correctly and I'm not sure as to where I'm wrong. Below is the code that I currently have.

If TypeOf e.Item Is GridDataInsertItem Then
        
            'Remove individuals from list if they exist already in the outcome memos table before binding the list.
            Dim newClients As RadDropDownList = CType(e.Item.FindControl("rdlClientNames"), RadDropDownList)
            Dim getAllClients As New IndividualsBase
            Dim indList As List(Of IndividualsBase) = getAllClients.SelectIndividuals(0,True,Nothing,0)

            Dim getIndividuals As New OutcomesMemos
            Dim indMemo As List(Of OutcomesMemos) = getIndividuals.SelectOutcomeMemos("Active")
            Dim totalInds As List(Of IndividualsBase)

            indMemo = indMemo.Where(Function(xMemos) Not indList.Contains(xMemos.AttendeeID)).ToList()

            If totalInds.Count = 0 Then
                Dim list As New RadDropDownList
                list.Items.Item(0).Text = "All Individuals Have Been Added"
            Else
                newClients.DataSource = totalInds
                newClients.DataTextField = "FullNameID"
                newClients.DataValueField = "AttendeeID"
                newClients.DataBind()
                Session("updateValue") = newClients.SelectedValue

            End If
        Else 
            Exit Sub
      End If

Open in new window

Trent AdamsApplication EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Your If is checking an empty list.

**  edit

Actually, how are you not getting errors in this code? The list is never initialized.
0
Trent AdamsApplication EngineerAuthor Commented:
I am, the code doesn't actually run unless I comment the above out. This is the part where I am having the problem:

'Remove individuals from list if they exist already in the outcome memos table before binding the list.
            Dim newClients As RadDropDownList = CType(e.Item.FindControl("rdlClientNames"), RadDropDownList)
            Dim getAllClients As New IndividualsBase
            Dim indList As List(Of IndividualsBase) = getAllClients.SelectIndividuals(0,True,Nothing,0)

            Dim getIndividuals As New OutcomesMemos
            Dim indMemo As List(Of OutcomesMemos) = getIndividuals.SelectOutcomeMemos("Active")
            Dim totalInds As List(Of IndividualsBase)

            indMemo = indMemo.Where(Function(xMemos) Not indList.Contains(xMemos.AttendeeID)).ToList()

Open in new window

0
käµfm³d 👽Commented:
What is the type of xMemos.AttendeeID? I'm guessing it's not IndividualsBase, which is what the things in your indList are. You need to convert the indList into things of the same type that AttendeeID is. What about:

Dim indList As List(Of Integer) = getAllClients.SelectIndividuals(0,True,Nothing,0).Select(Function (item) item.AttendeeID)

Open in new window

0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Trent AdamsApplication EngineerAuthor Commented:
I will try your solution and advise. Additional solutions are also welcome.
0
Trent AdamsApplication EngineerAuthor Commented:
Ok, so I had to go a different route. This is what I've come up with, and by no means am I familiar with LINQ syntax. But this is what I have, however, it is still returning all 413 records when it should return 0.

Dim clientToAdd As List(Of IndividualsBase) = indList.FindAll(Function(n) indMemo.Exists(Function(m) m.AttendeeID = n.AttendeeID))

Open in new window

0
it_saigeDeveloperCommented:
If you want to find all individuals that are missing an outcome:
Module Module1
	Sub Main()
		Dim individuals = (From i In Enumerable.Range(0, 50) Select New IndividualsBase With {.AttendeeID = i * 3, .Name = $"Individual{i * 3}"})
		Dim outcomes = (From i In Enumerable.Range(0, 15) Select New OutcomesMemos With {.AttendeeID = i * 2, .Company = $"Company{i * 2}"})
		Dim missing = individuals.Where(Function(individual) outcomes.All(Function(outcome) outcome.AttendeeID <> individual.AttendeeID))
		For Each individual In missing
			Console.WriteLine(individual)
		Next
		Console.ReadLine()
	End Sub
End Module

Class IndividualsBase
	Public Property AttendeeID() As Integer
	Public Property Name() As String
	Public Overrides Function ToString() As String
		Return $"AttendeeID: {AttendeeID}; Name = {Name}"
	End Function
End Class

Class OutcomesMemos
	Public Property AttendeeID() As Integer
	Public Property Company() As String
	Public Overrides Function ToString() As String
		Return $"AttendeeID: {AttendeeID}; Company = {Company}"
	End Function
End Class

Open in new window

Produces the following output -Capture.PNGIf you want to find all outcomes that are not assigned to individuals:
Module Module1
	Sub Main()
		Dim individuals = (From i In Enumerable.Range(0, 50) Select New IndividualsBase With {.AttendeeID = i * 3, .Name = $"Individual{i * 3}"})
		Dim outcomes = (From i In Enumerable.Range(0, 15) Select New OutcomesMemos With {.AttendeeID = i * 2, .Company = $"Company{i * 2}"})
		Dim missing = outcomes.Where(Function(outcome) individuals.All(Function(individual) individual.AttendeeID <> outcome.AttendeeID))
		For Each individual In missing
			Console.WriteLine(individual)
		Next
		Console.ReadLine()
	End Sub
End Module

Class IndividualsBase
	Public Property AttendeeID() As Integer
	Public Property Name() As String
	Public Overrides Function ToString() As String
		Return $"AttendeeID: {AttendeeID}; Name = {Name}"
	End Function
End Class

Class OutcomesMemos
	Public Property AttendeeID() As Integer
	Public Property Company() As String
	Public Overrides Function ToString() As String
		Return $"AttendeeID: {AttendeeID}; Company = {Company}"
	End Function
End Class

Open in new window

Produces the following output -Capture.PNG
-saige-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Trent AdamsApplication EngineerAuthor Commented:
Thank you all for the help and advice.
0
Trent AdamsApplication EngineerAuthor Commented:
Solution is accepted and applied a mixture of all the advice to achieve what I was needing.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.