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
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);
You can use a group join like:
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 });
精彩评论