【问题标题】:Linq record not in other tableLinq 记录不在其他表中
【发布时间】:2016-03-10 21:24:28
【问题描述】:

我想知道如何选择那些不在另一个表中的记录。

我有一个查询要显示一段时间内的所有股票

    var query = (from stk in ie.stocks
                         join s in ie.staffs on stk.stk_createby equals s.stf_id
                         where stk.stk_createdate >= startDate &&
                         stk.stk_createdate <= endDate
                         select new
                         {
                             StockID = stk.stk_id,
                             RefNo = stk.stk_ref_id,
                             Weight = stk.stk_weight,
                             Grade = stk.stk_grade,
                             Remark = stk.stk_remark,
                             StaffName = s.stf_name
                         }).ToList();

我还有另一个查询来显示所有已交付的库存。

                var query2 = (from ol in ie.orderLists
                              join stk in ie.stocks on ol.ol_stockid equals stk.stk_id
                              join dl in ie.deliveries on ol.ol_dlyid equals dl.dly_id
                              join s in ie.staffs on stk.stk_createby equals s.stf_id
                              where dl.dly_delivery_date >= startDate &&
                              dl.dly_delivery_date <= endDate
                              select new
                              {
                                  StockID = stk.stk_id,
                                  RefN = stk.stk_ref_id,
                                  Weight = stk.stk_weight,
                                  Grade = stk.stk_grade,
                                  Remark = stk.stk_remark,
                                  StaffName = s.stf_name
                              }).ToList();

所以我想要显示未交付的剩余库存。如何排除query2中的所有股票?

【问题讨论】:

    标签: c# asp.net linq webforms


    【解决方案1】:

    尝试除外方法。

    例如)

    var ret = query1.Except(query2);
    

    【讨论】:

    猜你喜欢
    • 2014-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-25
    • 2019-04-23
    • 2012-06-01
    相关资源
    最近更新 更多