Compare two instances of IQueryable

I have two instances IQueryable- objIQuerableAand objIQueryableB, and I want to get only those elements that are present in objIQuerableA, not in objIQuerableB.

One way is to use a foreach loop, but I'm wondering if there is a better method.

+3
source share
2 answers

Simple and direct.

var result = objIQuerableA.Except(objIQuerableB);
+8
source

The title says a comparison of two IQueryables. If you want to actually do a comparison to determine if both IQueryables contain the same results in the same query ....

var aExceptB = objIQuerableA.Except(objIQuerableB);
var bExceptA = objIQuerableB.Except(objIQuerableA);
var symmetricDiff = aExceptB.Union(bExceptA);
bool areDifferent = symmetricDiff.Any();
+1
source

Source: https://habr.com/ru/post/1708121/


All Articles