我需要根據一些標準生成一個完整的月報告。第一個條件是 - 我從用戶那里獲取匿名日期 ,在檢查所有條件后,它將生成全月報告。
我試圖生成報告,但這會回傳一份每日報告。除了月份,一切都很好。請幫助我做到這一點。
[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 == id)
.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!");
}
}
uj5u.com熱心網友回復:
你必須為這個月創造條件,你正在做的日期。所以這樣做。
.Where(x => x.LcOpenDate.Month == id.Month && x.LcOpenDate.Year == id.Year)
在這里,我假設兩者id都LcOpenDate來自相同的時區。
根據評論,LcOpenDate是DateTime?,所以你需要這樣做。
LcOpenDate.Value.Month和LcOpenDate.Value.Year
uj5u.com熱心網友回復:
DateTime給你一個完整的日期和時間,看起來像
2022-11-11 11:44:53 PM
可能發生的情況是,當您將資料存盤在資料庫中時,您忽略了時間。像這樣的東西:
var date = new DateTime(now.Year, now.Month, now.Day)
// 2022-11-11 12:00:00 AM
這是唯一可行的方法x.LcOpenDate == id。否則,它只會在您提供的精確時間回傳具有開放日期的專案,直到毫秒。試試這個:
.Where(x => x.LcOpenDate.Year == id.Year && x.LcOpenDate.Month == id.Month)
此外,如果您使用的是 .net 6 ,則可以使用DateOnly和TimeOnly
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/532778.html
