Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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
    ......
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
242 views
Welcome To Ask or Share your Answers For Others

1 Answer

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();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...