我已经编写了这段代码来从sql server连接两个表,现在我想用方法语法编写它。我该如何重写这段代码?
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();
答案 0 :(得分:1)
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();