I am trying to utilize LINQ to speed up the processing of a table that I have. I can get the expression to pull just one scenario, but not all that are required.
I have a table similar to the one above, but I’ve simplified it for this question. Date1 correlates with Thing1, Date2 correlates with Thing2, and Date3 correlates withThing3.
For each Employee I need to make sure that if Thing1 is true, then Date1 has a date. If Thing1 is false, then Date1 should not have a date.
Same applies for Date2/Thing2 and Date3/Thing3
Each date/thing discrepancy that doesn’t meet the above criteria would be exported to a new data table.
Thanks in advance and let me know if clarification is needed.
dt_input.AsEnumerable.Where(Function(x) Not( ((x("Thing1").ToString.Equals("TRUE") And Not String.IsNullOrEmpty(x("Date1").ToString)) Or (x("Thing1").ToString.Equals("FALSE") And String.IsNullOrEmpty(x("Date1").ToString))) And ((x("Thing2").ToString.Equals("TRUE") And Not String.IsNullOrEmpty(x("Date2").ToString)) Or (x("Thing2").ToString.Equals("FALSE") And String.IsNullOrEmpty(x("Date2").ToString))) And ((x("Thing3").ToString.Equals("TRUE") And Not String.IsNullOrEmpty(x("Date3").ToString)) Or (x("Thing3").ToString.Equals("FALSE") And String.IsNullOrEmpty(x("Date3").ToString)))) ).CopyToDataTable
(From d in YourDataTableVar.AsEnumerable
Let cs1 = new String(){"Date1","Date2","Date3"}
Let cs2 = new String(){"Thing1","Thing2","Thing3"}
Let dpc = cs1.Select(Function (x) DateTime.TryParse(d(x).toString.Trim, nothing)).toArray
Let tbc = cs2.Select(Function (y) CBool(d(y).toString.Trim)).toArray
Let chk = dpc.SequenceEqual(tbc)
Where chk
Select r = d).CopyToDataTable
cs1, cs2 could be externalized so it will not be done for each loop
the dpc, tbc constructions can be modified if needed e.g DateTimeParseExact…
Thank you all for your possible solutions, however I will no longer require a solution to this as the scope of the project changed, directly impacting the need for this.