Ki v2 Ki v2 - 3 months ago 24
C# Question

Lambda convert to LINQ

I don't know anything about lambda, and I can't even read a complicated lambda expression. I have this lambda code below that I want to convert into LINQ, but I don't know how.

var train = db.sample1
.Join(db.sample2, a => a.CertificateId, b => b.CertificateId, (a, b) => new { a, b })
.Where(x => x.a.Year.Value.Year == year && x.a.TrainingTypeId.Value == trainingTypeId && x.a.IsApproved.Value && x.b.EndDate >= DateTime.Now)
.Select(z => z.a).Distinct();

What I have tried so far and got stuck on:

var train = (from c in db.sample1
join in ts sample2 where a.CertificateId equals b.CertificateId


Lambda LINQ is still a link expression. However, the statement should look something like this:

var train2 = (from c in db.sample1
    join t in db.sample2
        on c.CertificateId equals t.CertificateId
        where c.Year.Value.Year == year && c.TrainingTypeId.Value == trainingTypeId
        && c.IsApproved.Value && t.EndDate >= DateTime.Now
        select c).Distinct();