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

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

This is the request I need:

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

How to do it?

Say that the board is a dataset / variable, and the category is a different dataset / variable, so I need something like board.Join (category) .Where (b => b.bid == c.cid) ( I know this is wrong, but only because you have an idea what I'm looking for, thanks for your help

+3
source share
2 answers

If you mean the syntax of the method, not the syntax of the linq query, 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);
+5

, :

var qry = boards.GroupJoin(
    categories,
    b => b.CategoryID,
    c => c.CategoryID,
    (x, y) => new { Board = x, Categories = y })
    .SelectMany(
    x => x.Categories.DefaultIfEmpty(),
    (x, y) => new { Board = x.Board, Category = y });
+2

All Articles