1

在 DF 4 vs 2010 上工作。使用 SalSalesOrderFinancial 表在 SalSalesOrderDetail 上加入时面临问题。

在此处输入图像描述

在 SalSalesOrderFinancial 中,一条记录的 SalesOrderDetailID=null。想要获取那些 SalesOrderDetailID 不存在于 SalSalesOrderFinancial 中的记录。

要获得所需的输出,请编写下面的 linq 语法,它正在工作。寻找更好的连接语法。有没有办法在一次连接中获得所需。

      var tempBDwithSODetail = (from p in this.Context.SalSalesOrderFinancials
                                          where p.SalesOrderDetailID != null
                                          select p.SalesOrderDetailID).AsEnumerable();

                var tempBDwithOutSODetail = (from p in this.Context.SalSalesOrderFinancials where p.SalesOrderDetailID == null select p).AsEnumerable();
                var querySOD = (this.Context.SalSalesOrderDetails.Where(item => !tempBDwithSODetail.Contains(item.SalesOrderDetailID))).AsEnumerable();

var tempBDetail = (from p in querySOD
                  join q in tempBDwithOutSODetail on p.SalesOrderID equals q.SalesOrderID
                                   where q.SalesOrderDetailID == null
                                   select new
                                   {
                                       q.SalesOrderID,
                                       p.SalesOrderDetailID,
                                       q.CurrencyID,
                                       q.BillingPolicyID,
                                       q.BillTypeID,
                                       q.BillingTypeID
                                   }).AsEnumerable();

如果有任何疑问,请询问。提前致谢。

4

1 回答 1

0

如果我得到你,你只需要简单的左连接SalSalesOrderDetailSalSalesOrderFinancial......

var query = (from u in this.Context.SalSalesOrderDetail
             join t in this.Context.SalSalesOrderFinancials 
                 on u.SalesOrderDetailID equals t.SalesOrderDetailID into JoinedList
             from t in JoinedList.DefaultIfEmpty()
             select new
             {
                 SalSalesOrderDetail = t,
                 SalSalesOrderFinancials = u
             })
             .Where(u => u.SalSalesOrderFinancials == null)
             .ToList();
于 2014-01-29T21:39:53.703 回答