Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# lambda expression question - how to join 2 tables using Lambda statements from the following SQL? [closed]

I have 2 tables, and I would like to join them using Lambda statements (not Linq but Lambda).

This is the query that I need:

SELECT
    c.*
FROM
    board as b
LEFT JOIN category as c ON
    b.cid = c.cid
WHERE
    b.bid = 1

How do I do this?

Say if board is a dataset/variable and category is an other dataset/variable then i want somethign like board.Join(category).Where(b=>b.bid==c.cid) ( i know this is wrong but just so you have an idea what i am looking for thank you so much for all your help


1 Answers

If you mean method syntax and not query syntax of linq then you can do

var results = context.boards.Where(b => b.bid == 1)
                            .DefaultIfEmpty()
                            .Join(context.categories, 
                                  b => b.bid,
                                  c => c.cid,
                                  (b, c) => c);
like image 107
Bala R Avatar answered Aug 15 '26 20:08

Bala R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!