I have two IEnumerable<dynamic> of data retrieved from database tables, called FullSet and InScopeSubSet .
The second IEnumerable<dynamic> is a subset of the first set (both sets have ChildID as their unique ID)
I would like to create a new IEnumerable<dynamic> that contains only items from x that do not occur in y
I have tried the following but it will not compile. It says:
“extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax”
var sql = "SELECT ChildID, FirstName, Surname FROM Child ORDER BY ChildID ASC";
var FullSet = DB.Query(sql);
sql = "
SELECT UserScope.ChildID, Child.FirstName, Child.Surname
FROM UserScope
INNER JOIN Child ON UserScope.ChildID=Child.ChildID
WHERE UserAccountID = @0 ORDER BY ChildID ASC
";
var InScopeSubSet = DB.Query(sql, UserAccount.UserAccountID);
var OutScopeSubSet = FullSet .Except(InScopeSubSet );
To resolve the compiler error, use its second suggestion:
If that’s the case, you are probably getting reference comparisons on objects that are not identical. You might be able to do it by implementing a custom IEqualityComparer. The call becomes
And DynamicChildIdComparer is: