Reputation: 1950
I'd like to get suggestion in both C# and VB.NET
I have two tables Employees and CafeLogs. Some employees can be cashiers and also customers at the Cafe shop.
Table structures:
Table relationship:
Employees table data:
EmployeeId, FirstName, LastName
5, Brown , Lexus
CafeLogs table data:
LogId, CashierId, EmployeeId, Value
Wanted Result :I want to show both Cashier name and Employee name like this from one query:
7 , Steven Gerald, Lours John, 1
Right now I know how to select only LogId, Employee's name, and , Value, not with Cashier name yet.
Dim query = From log In db.CafeLogs _
Join emp In db.Employees On emp.EmployeeId Equals log.EmployeeId _
Select log.LogId, emp.FirsName, emp.LastName, log.Value
Upvotes: 1
Views: 3215
Reputation: 134811
This should do it in C#:
var query = from log in db.CafeLogs
join emp in db.Employees on log.EmployeeId equals emp.EmployeeId
join cas in db.Employees on log.CashierId equals cas.EmployeeId
select new
{
log.LogId,
Employee = emp.FirstName + " " + emp.LastName,
ChargedBy = cas.FirstName + " " + cas.LastName,
log.Value
};
and the VB version:
Dim query = From log In db.CafeLogs _
Join emp In db.Employees On log.EmployeeId Equals emp.EmployeeId _
Join cas In db.Employees On log.CashierId Equals cas.EmployeeId _
Select _
log.LogId, _
Employee = emp.FirstName & " " & emp.LastName, _
ChargedBy = cas.FirstName & " " & cas.LastName, _
log.Value
Upvotes: 6