LINQ (joining two structures, one to many, showing min only) VB.net

Hi Experts,

I want to LINQ two structures:

EmployeeStructure
EmpID
LastName
FirstName
OfficeCode
End Structure

OfficeStructure
OfficeCode
OfficeName
ID (unique)
End Structure

LINQ the structures on OfficeCode.  There are many OfficeCodes associated with each employee, but I only want the one with the minimum ID.

Please help me create the LINQ statement that will return the following:

I want a list of employees (each employee is listed only once) with the one OfficeName that has the minimum ID.

Thanks,
pttoyAsked:
Who is Participating?
 
käµfm³d 👽Commented:
Ah. Yes it is. Just needed to be sure  = )

Here's an example:
Dim joined = From Employee In eList _
             Join Office In oList _
             On Employee.OfficeCode Equals Office.OfficeCode _
             Where Office.ID.Equals((From o In oList _
                                    Where o.OfficeCode = Office.OfficeCode _
                                    Select o.ID).Min()) _
            Select Employee, Office

For Each item In joined
    Console.Write(item.Employee.FirstName)
    Console.Write(" ")
    Console.Write(item.Employee.LastName)
    Console.Write(" ")
    Console.WriteLine(item.Office.ID)
Next

Open in new window

0
 
käµfm³d 👽Commented:
Is this Linq-to-Objects (collections), Linq-to-Sql, or Linq-to-Xml?
0
 
pttoyAuthor Commented:

I believe this is LINQ to objects.  To be specific, they are List(of structure).
0
 
pttoyAuthor Commented:
Thank You!
0
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.

All Courses

From novice to tech pro — start learning today.