我需要根据一些标准生成一个完整的月报告。第一个条件是-我从用户那里获取一个匿名词Date,在检查所有条件之后,它将生成完整的月份报告。
我试图生成报告,但这是返回一天明智的报告。除了这个月,一切都很好。请帮我做这个。
[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!");
}
}发布于 2022-11-12 04:47:04
你必须为这个月设定条件,你要在日期上做。所以就像这样吧。
.Where(x => x.LcOpenDate.Month == id.Month && x.LcOpenDate.Year == id.Year)这里我假设id和LcOpenDate都来自相同的时区。
根据注释,LcOpenDate是DateTime?,所以您需要这样做。
LcOpenDate.Value.Month和LcOpenDate.Value.Year
发布于 2022-11-12 04:50:05
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)https://stackoverflow.com/questions/74410414
复制相似问题