Please do not give me help in lamba
I have two tables.
Employees:
pk
name
ExpenseTeamMembers:
pk
expMgrPk
empPk
Example: pk expMgrPk empPk
1 7 81
2 7 101
3 13 99
4 13 22
5 13 56
Basically the first table is a list of employees and the second is a table for keeping track of which employees belong to which manager.
The first sql lookup works and mgr is getting me the pk of the selected name in the combo box.
What I am trying to do in the join is lookup the expMgrPk and see which employees belong to it and return their names instead of their pk. I am pretty off and need a little help. Again please do not give me help in lamba!! Thanks
private void cboManagers_SelectedIndexChanged(object sender, EventArgs e)
{
if (cboManagers != null)
{
string selectedMgr = (string)cboManagers.SelectedValue;
using (DataClasses1DataContext db = new DataClasses1DataContext())
{
int mgr = (from f in db.employees
where f.name == selectedMgr
select f.pk).FirstOrDefault();
var emps = (from m in db.employees
join t in db.expenseTeamMembers on m.pk equals t.pK
where t.expMgrPk == mgr
select m.name).ToList();
lstSelected.DataSource = emps;
}
}
}
In linq-to-sql, you can write joins more easily by writing two
fromstatements combined with awherestatement. Something like this:I’ve found this syntax to be easier and when your code is compiled, the query is converted to a traditional T-SQL join.