tags:

views:

52

answers:

1

Using VB.NET (3.5), i have an ArrayList of Employees. I'm trying to build an XML representation (to feed another system) and one of the fields is a simple incrementing ID, starting at 1. The code I currently have is:

Dim Emps = <Employees>
                    <%= From ee As Employee In Employees _
                        Select <Employee>
                                   <EmployeeID>1</EmployeeID>
                                   <DateOfBirth><%= ee.DOB %></DateOfBirth>
                                   <ZipCode>
                                       <Zip><%= ee.ZIP %></Zip>
                                   </ZipCode>
                               </Employee> %>
           </Employees>

How can I increment the EmployeeID field, I'm not sure how using this simple LINQ query.

Thanks.

A: 

Try this:

Dim Emps = <Employees>
                <%= From ee As Employee In Employees _
                    Select <Employee>
                               <EmployeeID><%= Employees.IndexOf(ee) + 1 %></EmployeeID>
                               <DateOfBirth><%= ee.DOB %></DateOfBirth>
                               <ZipCode>
                                   <Zip><%= ee.ZIP %></Zip>
                               </ZipCode>
                           </Employee> %>
       </Employees>
Vedran
Nice and simple! Thanks!
John T