diff --git a/src/OData.QueryBuilder/Conventions/Functions/IODataStringAndCollectionFunction.cs b/src/OData.QueryBuilder/Conventions/Functions/IODataStringAndCollectionFunction.cs
index 66612978..ac0058db 100644
--- a/src/OData.QueryBuilder/Conventions/Functions/IODataStringAndCollectionFunction.cs
+++ b/src/OData.QueryBuilder/Conventions/Functions/IODataStringAndCollectionFunction.cs
@@ -32,5 +32,10 @@ public interface IODataStringAndCollectionFunction
/// http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_concat
///
string Concat(string s1, string s2);
+
+ ///
+ /// http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_indexof
+ ///
+ int IndexOf(string columnName, string value);
}
}
diff --git a/src/OData.QueryBuilder/Expressions/Visitors/ODataOptionFilterExpressionVisitor.cs b/src/OData.QueryBuilder/Expressions/Visitors/ODataOptionFilterExpressionVisitor.cs
index fd12e209..0618362b 100644
--- a/src/OData.QueryBuilder/Expressions/Visitors/ODataOptionFilterExpressionVisitor.cs
+++ b/src/OData.QueryBuilder/Expressions/Visitors/ODataOptionFilterExpressionVisitor.cs
@@ -138,6 +138,11 @@ protected override string VisitMethodCallExpression(MethodCallExpression methodC
var toLower0 = VisitExpression(methodCallExpression.Arguments[0]);
return $"{nameof(IODataFunction.ToLower).ToLowerInvariant()}({toLower0})";
+ case nameof(IODataStringAndCollectionFunction.IndexOf):
+ var indexOf0 = VisitExpression(methodCallExpression.Arguments[0]);
+ var indexOf1 = VisitExpression(methodCallExpression.Arguments[1]);
+
+ return $"{nameof(IODataFunction.IndexOf).ToLowerInvariant()}({indexOf0},{indexOf1})";
case nameof(IConvertFunction.ConvertEnumToString):
return $"'{_valueExpression.GetValue(methodCallExpression.Arguments[0])}'";
case nameof(IConvertFunction.ConvertDateTimeToString):
diff --git a/test/OData.QueryBuilder.Test/ODataQueryOptionListTest.cs b/test/OData.QueryBuilder.Test/ODataQueryOptionListTest.cs
index 2c374ee8..5323d810 100644
--- a/test/OData.QueryBuilder.Test/ODataQueryOptionListTest.cs
+++ b/test/OData.QueryBuilder.Test/ODataQueryOptionListTest.cs
@@ -1090,9 +1090,21 @@ public void ODataQueryBuilderList_Filter_Method_Not_Supported_NotSupportedExcept
.Invoking(c => c
.For(s => s.ODataType)
.ByList()
- .Filter((s, f) => @string.IndexOf("t") == 1)
+ .Filter((s, f) => @string.Trim() == "s")
.ToUri())
- .Should().Throw().WithMessage($"Method {nameof(string.IndexOf)} not supported");
+ .Should().Throw().WithMessage($"Method {nameof(string.Trim)} not supported");
+ }
+
+ [Fact(DisplayName = "IndexOf Test => Success")]
+ public void ODataQueryBuilderList_Test_IndexOf()
+ {
+ var uri = _odataQueryBuilderDefault
+ .For(s => s.ODataType)
+ .ByList()
+ .Filter((s, f) => f.IndexOf(s.ODataKind.ODataCode.Code, "testCode") == 1)
+ .ToUri();
+
+ uri.OriginalString.Should().Be("http://mock/odata/ODataType?$filter=indexof(ODataKind/ODataCode/Code,'testCode') eq 1");
}
}
}