我有以下条目的数据表:
**Companyid Deptid Location Employeeid Employeename Employeeage**
001 D001 CA 0001 Jason Bourne 57
001 D001 CA 0002 Will Smith 45
001 D001 NV 0003 Kurt Rusell 47
002 D002 CA 0008 Panda 57
002 D002 CA 0009 Fox 45
002 D002 NV 0010 Wolf 35
我希望使用 Linq 在 C# 中创建 XML。公司 ID、部门 ID 和位置的组合将被视为唯一。我希望创建一个新的公司元素以及该公司元素下的所有员工。XML 应该看起来像
<companies>
<company companyid="001" DeptID="D001" Location="CA">
<Employee id="0001" Employeename="Jason Bourne" Employeeage=57/>
<Employee id="0002" Employeename="Will Smith" Employeeage=45/>
</company>
<company companyid="001" DeptID="D001" Location="NV">
<Employee id="0003" Employeename="Kurt Rusell" Employeeage=47/>
</company>
<company companyid="002" DeptID="D002" Location="CA">
<Employee id="0008" Employeename="Panda" Employeeage=57/>
<Employee id="0009" Employeename="Fox" Employeeage=45/>
</company>
<company companyid="002" DeptID="D002" Location="NV">
<Employee id="0010" Employeename="Wolf" Employeeage=35/>
</company>
</companies>
任何帮助将不胜感激。数据表也按 companyid、deptid、location 排序