Do can I convert this query syntax linq expression to method syntax?

236 Views Asked by At

I've written this code to join two tables together from sql server, now I want to write this as in method syntax. How can I rewrite this code?

LinqToLoginDataContext lnqdore = new LinqToLoginDataContext();
var f = (from k in lnqdore.Table_Years
         join h in lnqdore.Table_Dores on k.Id equals h.FK_Year
         where h.Id == (int)dataviewDore.CurrentRow.Cells["Id"].Value
         select k).Single();
1

There are 1 best solutions below

3
On BEST ANSWER
var f = lnqdore.Table_Years
    .Join(lnqdore.Table_Dores, k => k.ID, h => h.FK_Year, (k, h) => new { k, h })
    .Where(res => res.h.ID == (int)dataviewDore.CurrentRow.Cells["Id"].Value)
    .Select(res => res.k)
    .Single();