I have 2 list of guids as:
IEnumerable<dynamic> userids = null;
IEnumerable<dynamic> lsCheckedUsers = null;
The userids and lsCheckedUsers list are populated from a SQL database using dapper.
I now wish to find all userids that are not in lsCheckedUsers.
I have tried the following
var userdifference = userids.Where(i => !lsCheckedUsers.Contains(lsCheckedUsers));
var userdifference = userids.Except(lsCheckedUsers);
None of the above actual returns the difference between the 2.
How do I get the difference of guids that do not exist in both.
I am certain that lsCheckedUsers has Guids that are in userids
This is correct:
var userdifference = userids.Except(lsCheckedUsers);
It will work if both of your IEnumerable<dynamic>
actually contain Guids
. Print out or inspect the items in each to make sure they are Guids
.
You should really be using IEnumerable<Guid>
and cast the incoming items to Guids
if this is what you are expecting. It will hopefully prevent errors like the one you are potentially seeing.
Something along those lines..
var difference = list1.Where (e => !list2.Any(a => a == e))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With