Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
258 views
in Technique[技术] by (71.8m points)

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

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

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...