ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
2,859 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi friends,
I wonder if there is a way to use TrueForAll
for IEnumerable<OrderDetail>
? I am trying to check if all of the status = 1
or not. How can I check if all statuses in details are 1 or not?
Thank you.
var details = _viewOrderDetailsByOrderIdUseCase.ExecuteAsync(reportList[0].OrderId);
public async Task<IEnumerable<OrderDetail>> GetOrderDetailsByOrderId(int orderId)
{
return await _db.OrdersDetail
.Where(x => x.OrderId == orderId && x.IsActive == 1)
.Include(x => x.Order)
.OrderBy(x => x.VendorId).ToListAsync();
}
public class Order
{
public int Id { get; set; }
[Required]
public DateTime OrderDateTime { get; set; }
[Required]
[MaxLength(250)]
public int CustomerId { get; set; }
public string Status { get; set; }
[MaxLength(50)]
public string DoneBy { get; set; }
public List<OrderDetail> OrderDetails { get; set; }
public Customer Customer { get; set; }
}
public class OrderDetail
{
public int Id { get; set; }
[Required]
[MaxLength(100)]
public string ProductCode { get; set; }
[MaxLength(250)]
public string? ProductName { get; set; }
[Required]
public int Quantity { get; set; }
[Required]
public double BuyUnitPrice { get; set; }
public double CostRatio { get; set; }
public double UnitCost { get; set; }
public double TotalBuyPrice { get; set; }
public double? SellUnitPrice { get; set; }
public double? TotalSellPrice { get; set; }
[MaxLength(150)]
public string? ShippingNumber { get; set; }
public string? Status { get; set; }
[MaxLength(150)]
public string? TrackingNumber { get; set; }
[MaxLength(400)]
public string? Description { get; set; }
public string? Currency { get; set; }
public string? CustomerStockCode { get; set; }
public string? CustomerOrderNumber { get; set; }
public int IsActive { get; set; }
public double? TotalUnitCost { get; set; }
public int OrderId { get; set; }
public int VendorId { get; set; }
public string? Warehouse { get; set; }
public string? PaymentStatus { get; set; }
public Order Order { get; set; }
public Vendor Vendor { get; set; }
[DataType(DataType.DateTime)]
public DateTime? CompletionDateTime { get; set; }
}
An alternative if the majority of queries are looking at IsActive would be to use HasQueryFilter and IgnoreQueryFilter. I don't see using TrueForAll working in your query and would keep it as is assuming (and it looks so) its working.
Added classes, Order and OrderDetail are related.
Thanks for the details, you should join the order table first then include your orderdetails then filter it according to your condition.