Using LINQ to Objects to find items in one collection that do not match another

后端 未结 8 1869
清酒与你
清酒与你 2020-12-29 05:04

I want to find all items in one collection that do not match another collection. The collections are not of the same type, though; I want to write a lambda expression to spe

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 05:47

    Its better if you left join the item and filter with null condition

    var finalcertificates = (from globCert in resultCertificate
                                             join toExcludeCert in certificatesToExclude
                                                 on globCert.CertificateId equals toExcludeCert.CertificateId into certs
                                             from toExcludeCert in certs.DefaultIfEmpty()
                                             where toExcludeCert == null
                                             select globCert).Union(currentCertificate).Distinct().OrderBy(cert => cert.CertificateName);
    

提交回复
热议问题