Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write IQueryable Join using lambda?

Tags:

c#

iqueryable

I have next table:

MyTable
(
ParentId Integer,
Type Integer,
ProdId String,
Date DateTime,
Status Integer
);

I want to query as next:

var res = from tout in myTable.Where(t1 => t1.Type == 1)
                join tin in myTable.Where(t2 => t2.Type != 1)
        on tout.ParentId equals tin.ParentId
                where tout.ProdId == tin.ProdId && tout.Status > tin.Status
                orderby tout.Date
                select new MyTableStructure
                {
            ...
        };

How to write same as IQueryable using lambda?

like image 415
Ksice Avatar asked Mar 10 '23 15:03

Ksice


1 Answers

Something like this

var query1 = myTable.Where(t1 => t1.Type == 1);
var query2 = myTable.Where(t2 => t2.Type != 1);
var join = query1.Join(query2, x => x.ParentId, y => y.ParentId, (query1, query2) => new { query1 , query2 }).Where(o => o.query1.ProdId == o.qyuery2.prodId).......

your order by next and Something

like image 156
Vecchiasignora Avatar answered Mar 19 '23 21:03

Vecchiasignora