首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >连接表中的和列,以便使用LINQ获得计算值

连接表中的和列,以便使用LINQ获得计算值
EN

Stack Overflow用户
提问于 2022-11-13 15:47:10
回答 1查看 35关注 0票数 0

在下面的上下文中,我根据一些标准加入了两个表。现在,我需要从calculate total value的结果joined table

代码语言:javascript
复制
[HttpGet("inner-join/{id}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetReport(DateTime id)
{
  try
  {
    IEnumerable<BTBPending> objBTBPendingList = _unitOfWork.BTBPending.GetAll(includeProperties: "ProformaInvoice,ContractList,SupplierList,CountryList,ItemList,BuyerList,StyleList,TradeTermList,ErpRemarksList,StatusList,LcNoList,UdAmendList");

    IEnumerable<ProformaInvoice> objProformaInvoiceList = _unitOfWork.ProformaInvoice.GetAll(includeProperties: "ActualContract,ContractList,SupplierList,CountryList,ItemList,BuyerList,StyleList,TradeTermList");


    var query = objBTBPendingList
        .Where(x => x.LcOpenDate.Value.Year == id.Year && x.LcOpenDate.Value.Month == id.Month)
        .Where(x => x.CountryListId == 26)
        .Where(x => x.StatusListId == 12 || x.StatusListId == 13 || x.StatusListId == 14)
        .Join(objProformaInvoiceList,
              btbPending => btbPending.ContractListId,
              pi => pi.ContractListId, 
              (btbPending, pi) => new
              {
                LcNo = btbPending.LcNoList,
                Value = btbPending.PiValue,

                ContractNo = pi.ContractList,
                Buyer = pi.BuyerList,
                PiNo = pi.PINo,
                Supplier = pi.SupplierList,
                Item = pi.ItemList
              }).ToList();


     return Ok(query);
   }
 catch (Exception ex)
   {
     return StatusCode(500, "Internal Server Error, Please Try Again Leter!");
   }
}

在加入这两个表之后,我需要从下面的sum列返回Value = btbPending.PiValueValue = btbPending.PiValue列是表的after joining

代码语言:javascript
复制
.Join(objProformaInvoiceList,
      btbPending => btbPending.ContractListId,
      pi => pi.ContractListId, 
      (btbPending, pi) => new
      {
      LcNo = btbPending.LcNoList,
      Value = btbPending.PiValue,

      ContractNo = pi.ContractList,
      Buyer = pi.BuyerList,
      PiNo = pi.PINo,
      Supplier = pi.SupplierList,
      Item = pi.ItemList
      }).ToList();
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-14 05:45:35

你可以像这样计算var sum = query.Select(c => c.Value).Sum();的和

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74422448

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档