Adu Adu - 3 months ago 10
Vb.net Question

How two compare two array list items in linq query vb.net

I have two querys(qry1 returning [a1],[a2]; qry2 returning [a1],[a2],[a3]). So i want to compare these two queries . If they are not equal perform some function. Below is the query i am trying.i dont want to compare with 'count' operator.

Dim Qry1 = (From x In db1.Approvals _
Where x.ID = tId _
And x.APPROVALID = GetRqstID(thisId) _
Select x.APPROVERID).ToList()


Dim Qry2 = (From x In db.Resources _
Join y In db.Users On x.USER_ID Equals y.USER_ID _
Where x.ID = tskIdIn _
And x.TYPE = rsrcType _
Order By y.FIRST_NAME _
Select x.USER_ID).ToList()


If ((Qry1.ToArray) <> (Qry2.ToArray)) Then
---
---
End If

Answer
if (Qry1.Count() != Qry2.Count() || 
    Qry1.Except(Qry2).Count() > 0 ||
    Qry2.Except(Qry1).Count() > 0)  
 // not the same.

I do the count check first because of short circuit it will speed up most cases. It is not needed if you are doing the other two.

https://msdn.microsoft.com/en-us/library/bb300779%28v=vs.110%29.aspx