【问题标题】:How to write IQueryable Join using lambda?如何使用 lambda 编写 IQueryable Join?
【发布时间】:2017-08-04 15:39:05
【问题描述】:

我有下一张桌子:

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 相同的写法?

【问题讨论】:

标签: c# iqueryable


【解决方案1】:

类似的东西

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

next 和Something 的订单

【讨论】:

  • 非常感谢!唯一的注意事项(我花了一些时间才意识到到底出了什么问题) - new { query2 , query1 } - 应该有明智的相反顺序,以匹配原始连接
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-06
  • 2014-06-13
  • 1970-01-01
  • 2019-08-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多