M
MRM256
Guest
Hi Everyone
Karen Payne helped me with a LINQ query written to work on a VB.NET console application.
Using various VB.NET to C# converters I took my working VB LINQ query and converted it into its C# equivalent. From observation only I noticed a specific line in the VB.NET query was missing. I will post both the working one first followed by the hosed up one.
Working VB.NET code:
Dim query = From Team In dtTeams.AsEnumerable
Join Emp In dtEmp.AsEnumerable
Join Pos In dtPostion.AsEnumerable
On Emp.Field(Of String)("EmpID") Equals Pos.Field(Of String)("AssignedEmployee")
On Team.Field(Of String)("TeamID") Equals Pos.Field(Of String)("AssignedTeam")
Where ((Not (Emp.Field(Of String)("EmpID") = strEmpID)))
Select New With
{
.EmployeeID = Emp.Field(Of String)("EmpID"), _
.EmployeeName = Emp.Field(Of String)("EmpName"), _
.PositionName = Pos.Field(Of String)("PositionName"), _
.TeamName = Team.Field(Of String)("TeamName")
}
Hosed up C# code
var query = from Team in dtTeams.AsEnumerable()
join Emp in dtEmp.AsEnumerable() on Team.Field<string>("TeamID")
equals (Pos.Field<string>("AssignedTeam"))
where ((!(Emp.Field<string>("EmpID") == strEmpID)))
select new
{
EmployeeID = Emp.Field<string>("EmpID"),
EmployeeName = Emp.Field<string>("EmpName"),
PositionName = Pos.Field<string>("PositionName"),
TeamName = Team.Field<string>("TeamName")
};
The Missing code line is: Join Pos In dtPostion.AsEnumerable. Under code line Join Emp In dtEmp.AsEnumerable.
The C# version returns this error: The name 'Pos' is not in scope on the right side of 'equals'. Consider swapping the expressions on either side of 'equals'. This does not make any since. I tried it. Didn't work. All I did was swap the two terms on each side of the 'equals' statement.
Can anyone explain why it works in VB.NET and not C#.
Thanks,
MRM256
Continue reading...
Karen Payne helped me with a LINQ query written to work on a VB.NET console application.
Using various VB.NET to C# converters I took my working VB LINQ query and converted it into its C# equivalent. From observation only I noticed a specific line in the VB.NET query was missing. I will post both the working one first followed by the hosed up one.
Working VB.NET code:
Dim query = From Team In dtTeams.AsEnumerable
Join Emp In dtEmp.AsEnumerable
Join Pos In dtPostion.AsEnumerable
On Emp.Field(Of String)("EmpID") Equals Pos.Field(Of String)("AssignedEmployee")
On Team.Field(Of String)("TeamID") Equals Pos.Field(Of String)("AssignedTeam")
Where ((Not (Emp.Field(Of String)("EmpID") = strEmpID)))
Select New With
{
.EmployeeID = Emp.Field(Of String)("EmpID"), _
.EmployeeName = Emp.Field(Of String)("EmpName"), _
.PositionName = Pos.Field(Of String)("PositionName"), _
.TeamName = Team.Field(Of String)("TeamName")
}
Hosed up C# code
var query = from Team in dtTeams.AsEnumerable()
join Emp in dtEmp.AsEnumerable() on Team.Field<string>("TeamID")
equals (Pos.Field<string>("AssignedTeam"))
where ((!(Emp.Field<string>("EmpID") == strEmpID)))
select new
{
EmployeeID = Emp.Field<string>("EmpID"),
EmployeeName = Emp.Field<string>("EmpName"),
PositionName = Pos.Field<string>("PositionName"),
TeamName = Team.Field<string>("TeamName")
};
The Missing code line is: Join Pos In dtPostion.AsEnumerable. Under code line Join Emp In dtEmp.AsEnumerable.
The C# version returns this error: The name 'Pos' is not in scope on the right side of 'equals'. Consider swapping the expressions on either side of 'equals'. This does not make any since. I tried it. Didn't work. All I did was swap the two terms on each side of the 'equals' statement.
Can anyone explain why it works in VB.NET and not C#.
Thanks,
MRM256
Continue reading...