zoukankan      html  css  js  c++  java
  • LINQ踩坑记录

    1、join into 解析为groupjoin(组连接),但是直接对iqueryable做组连接报错,比对了一下之前一个项目中似乎是可以的,是不是环境不一样的原因呢,有待考证,当前的解决办法如下

    //只能通过异步的方式取LIST再groupjoin不然不成功,

    //控制器在调用这个异步方法时也要返回 Task或者await
    var inorders = await context.t_inorders.AsNoTracking().ToListAsync();
    var inorderdetails = await context.t_inorderdetais.AsNoTracking().ToListAsync();
    var products = await context.t_products.AsNoTracking().ToListAsync();


    var queryGP = from inorder in inorders
    where inorder.state == 1 && inorder.orderstate < 4 && inorder.orderstate > 1
    join detail_n in
    (from detail in inorderdetails
    join product in products on detail.productid equals product.id
    select new
    {
    detail.productid,
    detail.orderid,
    detail.alreadybindcount,
    detail.alreadycount,
    detail.productnum,
    product.productname

    }) on inorder.id equals detail_n.orderid into details
    select new
    {
    inorder.ordercode,
    inorder.tripcode,
    inorder.suppliercode,
    inorder.suppliername,
    details
    };
    var obj = queryGP.ToList();

    2、如果是要借助join into实现左联接的功能却不受影响,是因为没有被解析为groupjoin的原因吗?


    var A = context.t_inorders.AsNoTracking<t_inorder>();
    var B = context.t_inorderdetais.AsNoTracking<t_inorderdetai>();
    var C = context.t_products.AsNoTracking<t_product>();

    var queryGP1 = from inorder in A
    where inorder.state == 1 && inorder.orderstate < 4 && inorder.orderstate > 1
    join detail_n in
    (from detail in B
    join product in C on detail.productid equals product.id
    select new
    {
    detail.productid,
    detail.orderid,
    detail.alreadybindcount,
    detail.alreadycount,
    detail.productnum,
    product.productname

    }) on inorder.id equals detail_n.orderid into details
    from d1 in details.DefaultIfEmpty()
    select new
    {
    inorder.ordercode,
    inorder.tripcode,
    inorder.suppliercode,
    inorder.suppliername
    };
    var obj1 = queryGP1.ToList();

  • 相关阅读:
    HDU-2544-最短路(floyd)
    HDU-1009-肥鼠交易
    BZOJ-3029: 守卫者的挑战 (期望DP)
    2017年10月23日23:58:04
    BZOJ-2456: mode (神题)
    BZOJ-4542: [Hnoi2016]大数 (莫队算法)
    BZOJ-2120: 数颜色 (带修改莫队)
    BZOJ-2654: tree (kruskal)
    BZOJ-1040: [ZJOI2008]骑士 (树形DP)
    BZOJ-3505: [Cqoi2014]数三角形 (容斥原理+排列组合)
  • 原文地址:https://www.cnblogs.com/yzmn/p/14132555.html
Copyright © 2011-2022 走看看