Andreas
Andreas

Reputation: 301

Lambda expression help

I have a question how to write a lambda expression, i have it working in a mssql query like this:

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 using lambda expression was this:

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

But since KUNDs and KundInfo is two different kind of objects that wont work...i could go like this:

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

But that would just give me a list with strings with KUNDs.KUNDNR when i would really like to get a list with KUNDs objects back.

How can i do this?

Help would be very appreciated!

Upvotes: 3

Views: 729

Answers (1)

manji
manji

Reputation: 47968

db.KUNDs.Where(k => !db.KundInfos.Any(ki => k.KUNDNR == ki.KundID.ToString()))
        .OrderBy(k => k.KUNDNR);

Upvotes: 9

Related Questions