The Dynamic linq project does not support 'contains' natively, I had the same requirement and had to download the source and modify it to support it.
I have lost the ability to keep up with any nuget updates, but the solution now works for our needs. I can't find where I found this, but this is how I did it.
Edit the dynamic.cs file and add the following to around line 566:
interface IEnumerableSignatures
{
bool Contains(object selector); // Add this
void Where(bool predicate);
//...
// Then around line 628 add a new keyword:
static readonly string keywordOuterIt = "outerIt";
static readonly string keywordIt = "It";
//...
// above ParameterExpression It; add
ParameterExpression outerIt;
// In ParseIdentifier add
if (value == (object)keywordOuterIt) return ParseOuterIt();
//Then add that method
Expression ParseOuterIt()
{
if (outerIt == null)
throw ParseError(Res.NoItInScope);
NextToken();
return outerIt;
}
// In ParseAggreggate, add:
outerIt = it;
if (signature.Name == "Min" || signature.Name == "Max")
{
typeArgs = new Type[] { elementType, args[0].Type };
}
else
{
typeArgs = new Type[] { elementType };
}
if (args.Length == 0)
{
args = new Expression[] { instance };
}
else
{
// add this section
if (signature.Name == "Contains")
args = new Expression[] { instance, args[0] };
else
{
args = new Expression[] { instance, Expression.Lambda(args[0], innerIt) };
}
}
// In CreateKeyWords()
d.Add(keywordOuterIt, keywordOuterIt); // Add this
I don't know if we can upload source here, but I've been maintaining my own copy of Dynamic.cs, and trying to keep it up to date with the version on nuget. I'll be happy to upload it if you want. I just don't remember where I got all this, because searching for contains on Dynamic linq mostly yields the wrong results - pointing to string contains, not IEnumerable.contains.