问题
Issue with the search which has an integer contains predicate clause.
I have generated linq expression as below
This works fine if the field is a string field.
{f => (True AndAlso f.MyStringField.Contains("987"))}
But this does not work when i convert it to string. For example i am having an integer field say myIntField.
{f => (True AndAlso f.XYZ.myIntField.ToString().Contains("160"))}
I have added the piece of code which used for getting the query. It looks like some toString() is getting overriden somewhere,
if (propr.Type == typeof(string))
{
var body = Expression.Call(propr, method, value);
var lambda = Expression.Lambda<Func<T, bool>>(body, param);
predicate = predicate.And(lambda);
}
else
{
MethodInfo toStringMethod = typeof(object).GetMethod("ToString" );
MethodInfo methodinfo = typeof(string).GetMethod("Contains", new Type[] { });
value = Expression.Constant(property.Value);
var memberToStringBody = Expression.Call(propr, toStringMethod);
var body = Expression.Call(memberToStringBody, methodinfo, value);
var lambda = Expression.Lambda<Func<T, bool>>(body, param);
predicate = predicate.And(lambda);
}
来源:https://stackoverflow.com/questions/59209788/issue-with-cosmos-db-query-using-contains