Issue with cosmos db query using Contains

喜你入骨 提交于 2019-12-13 02:51:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!