I think it is easier to translate SQL using query comprehension syntax instead of lambda syntax.
General rules:
- Translate inner queries into separate query variables
- Translate SQL phrases in LINQ phrase order
- Use table aliases as range variables, or if none, create range
variables from table names abbreviations - Translate IN to Contains
- Translate SQL functions such as DISTINCT or SUM into function calls
on the entire query. - Create anonymous objects for multi-column grouping or joining
Using these rules, you should get something like:
var ans = from t in tblTeamType
join p in ProjInformation on t.team_id equals p.teamId
join pj in projProject on p.projectId equals pj.projectId
join ph in ProjInfoAdditionalHrs on new { p.teamId, p.Id } equals new { ph.teamId, ph.proJinfold }
select new {
ph.Id,
projInfoId = p.Id,
ph.Title,
ph.AdditionalHours,
ph.AdditionalCost,
ph.InsertDate,
ph.InsertBy,
ph.LastUpdateDate,
ph.LastUpdateBy,
ph.TeamId,
ph.ProjInfoId
};
solved Write an INNER JOIN in LINQ