IEnum object True for All

Cenk 946 Reputation points
2023-02-03T04:39:43.0233333+00:00

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; }

    }
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
3,997 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,926 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,011 Reputation points
    2023-02-03T11:52:16.87+00:00

    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.

    0 comments No comments