如何使用lambda编写IQueryable Join?

时间:2017-03-14 10:37:43

标签: c# iqueryable

我有下一张桌子:

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

我想查询下一个:

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
                {
            ...
        };

如何使用lambda编写与IQueryable相同的内容?

1 个答案:

答案 0 :(得分:2)

像这样的东西

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).......

你的订单接下来和Something