提示不支持 返回

SqlSugar 沟通中
6 91
该叫什么 bill 发布于1周前
悬赏:0 飞吻


var list = db.Queryable<SReceiptStandardDet>()
                .LeftJoin<SReceiptStandard>((it, h) => it.Dno == h.Dno)
                .GroupBy((it, h) => new { it.Dno, it.Ccode, it.Ccodename, it.MSrcdocno, it.MSrcdoclineno, h.Suppliername, h.Code, h.Wcode })
                .Where(it => it.Dno == dno && it.Ccode == itemcode)
                .Select((it, h) => new RcvDetsSum
                {
                    Dno = it.Dno,
                    Ccode = it.Ccode,
                    Ccodename = it.Ccodename,
                    MSrcdocno = it.MSrcdocno + "_" + it.MSrcdoclineno,
                    Suppliername = h.Suppliername,
                    po = it.MSrcdocno,
                    polineno = it.MSrcdoclineno,
                    wcode = h.Code + "-" + h.Wcode,
                    Qty = SqlFunc.AggregateSum(SqlFunc.IF(!it.Bcode.Contains("/")).Return(it.Qty)
                    .ElseIF(
                        SqlFunc.Subqueryable<SReceiptStandardDet>().Where(A=>A.Dno==it.Dno && A.Ccode == it.Ccode 
                        && A.Bcode.StartsWith(it.Bcode.Substring(0,it.Bcode.IndexOf("/")))).ToList().Count.ToString()
                        ==it.Bcode.Substring(it.Bcode.IndexOf("/")+1).Substring(0,1)
                        ).Return(1)
                    .End(0))
                })
                .ToList();

            return list;

调试时 说是不支持,但是这里也不知道改怎么来写了,就是子查询里面判断下是否记录齐全. 齐全return1,否则 0. 有什么好的办法吗?

image.png

热忱回答6

  • subquery没有这种语法 .ToList().Count.ToString()

    0 回复
  • bill bill VIP0
    1周前

    有什么更好的办法可以做到这个需求吗? 不一定用tolist().count,

    0 回复
  • select(it=>sqlfunc.XXXCount().tostring) 改成这样

    0 回复
  •  .ToList().Count.ToString()  这个替换成上面的

    0 回复
  • bill bill VIP0
    1周前
      var list = db.Queryable<SReceiptStandardDet>()
                    .Where(it => it.Dno == dno && it.Ccode == itemcode && it.MSrcdocno == PoBillNo && it.MSrcdoclineno == PoEntryID).ToList();
    
                List<RcvDetsSum> detSum = new List<RcvDetsSum>();
                foreach (var det in list)
                {
                    var ll = detSum.Find(it => it.Ccode == det.Ccode);
                    if (ll == null)
                    {
                        RcvDetsSum rd = new RcvDetsSum();
                        rd.Ccode = det.Ccode;
                        rd.Dno = det.Dno;
                        rd.po = PoBillNo;
                        rd.polineno = PoEntryID;
                        if (det.Bcode.Contains("/"))
                        {
                            if (det.Bcode.EndsWith("/1"))
                            {
                                rd.Qty = GetRecvDetQtysByBcode(det.Dno, PoBillNo, PoEntryID, det.Bcode);
                            }
                            else
                            {
                                rd.Qty = 0;
                            }
                        }
                        else
                        {
                            rd.Qty = det.Qty;
                        }
                        detSum.Add(rd);
                    }
                    else
                    {
    
    
                        if (det.Bcode.Contains("/"))
                        {
                            if (det.Bcode.EndsWith("/1"))
                            {
                                ll.Qty += GetRecvDetQtysByBcode(det.Dno, PoBillNo, PoEntryID, det.Bcode);
                            }                       
                        }
                        else
                        {
                            ll.Qty += det.Qty;
                        }
                    }
                }
                  
                return detSum;
     private int GetRecvDetQtysByBcode(string dno,string po,string poentryid,string bcode)
            {
                string bcodeBefore = bcode.Replace("/1", "");
                int index = bcodeBefore.IndexOf("/");
                string t1 = bcodeBefore.Substring(index+1);
    
                var list = db.Queryable<SReceiptStandardDet>()
                   .Where(it => it.Dno == dno && it.Bcode.Contains(bcodeBefore) && it.MSrcdocno == po && it.MSrcdoclineno == poentryid).ToList();
    
                if (list.Count == int.Parse(t1))
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
    
    
            }
    0 回复
  • bill bill VIP0
    1周前

    @bill:改成在内存中来处理,不用在 数据库一次性处理完,虽然牺牲了一些性能, 但是能达到我想要的效果. 我还有一个想法 就是用存储过程 或者函数  在数据库实现,然后sugar中去调用.

    0 回复