Lambda expression helps

I have a question how to write a lambda expression, it works for me in the mssql request, for example:

SELECT KUNDNR 
FROM halldb.dbo.KUND
wWHERE NOT EXISTS 
(
    SELECT KundID 
    FROM halldb.dbo.KundInfo 
    WHERE KUNDNR = CONVERT(Varchar(50), KundInfo.KundID)
)
ORDER BY KUNDNR

And what I was trying to use a lambda expression was as follows:

db.KUNDs.Select(x => x).Except(db.KundInfos.Select(x => x));

But since KUNDs and KundInfo are two different types of objects that don't work ... I could do this:

db.KUNDs.Select(x => x.KUNDNR).Except(db.KundInfos.Select(x => x.KundID.ToString()));

But that just gives me a list with strings with KUNDs.KUNDNR when I really would like to get a list with KUNDs objects.

How can i do this?

Help would be greatly appreciated!

+3
source share
1 answer
db.KUNDs.Where(k => !db.KundInfos.Any(ki => k.KUNDNR == ki.KundID.ToString()))
        .OrderBy(k => k.KUNDNR);
+9
source

All Articles