Verify that all the fields in a list are equal

0

I have two related lists in C #:

public class HandlingUnit 
{
  [StringLength(18)]
        [ExcelColumn("Handling Unit")]
        public String HandlingUnit { get; set; }

        [ExcelColumn("Created on")]
        public DateTime DateShipped { get; set; }

        [ExcelColumn("Packaging materials")]
        [StringLength(50)]
        public String Material { get; set; }

        [NotMapped]
        [ExcelColumn("Material")]
        public String MaterialNumber { get; set; }
}

 public class Batches
    {
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        [StringLength(10)]
        public String Batch { get; set; }
        public decimal Quantity { get; set; }
        public String Delivery { get; set; }
        public String ObjectKey { get; set; }
        public String Sterilizer { get; set; }

        public String Material { get; set; }

        [ForeignKey("Handling")]
        public String HandlingUnit { get; set; }
        public virtual HandlingUnits Handling {get;set;}

        public int? StatusID { get; set; }
        public virtual StatusHandlingUnit StatusH { get; set; }

        public byte Completed { get; set; }

}

I want to verify that all the batch associated with a specific Handling Unit, I have the status = completed otherwise I would launch a false or something like that. How could I do this with Linq? Is there any possibility?

    
asked by AlejandroMst 17.08.2018 в 16:21
source

1 answer

0

Assuming you have a list called batches and variable handlingUnitBuscado , it could be something like this:

batches
  .Where(b => b.HandlingUnit == handlingUnitBuscado)
  .All(b => b.StatusH == StatusHandlingUnit.Completed) 

What we are doing there is:

  • Filter the list, with the Where , leaving only those that have the handling unit searched.
  • Checking that all the elements fulfill the condition of being in the Completed state, using All .
  • answered by 17.08.2018 в 17:09