Search code examples
sqllinqodata

how do I compare values from List using simple Odata filter?


How do I write a filter which will compare Mylist-values to MyKeyTable-values?

I tried something like the following:

List<string> Mylist = new List<string>();
Mylist.Add("Welcome");
Mylist.Add("Hello");

var output = await client.For<MyKeyTable>()  
                         //this is wrong I knew I need to correct this        
                         .Filter(Mylist.Contains(x=>x.Key))
                         .FindEntriesAsync();

So output will come with all the values whoes Key-value matches as welcome and hello

Thanks in advance.


Solution

  • Done I tried it using custom expression

    ParameterExpression pe = Expression.Parameter(typeof(MyTableClass), "entity");
                Expression expression = null;
                Expression predicateBody = null;
                Expression leftExpression = Expression.Property(pe, "Key");
                Expression rightExpression = Expression.Constant("Welcome");
                expression = Expression.Equal(leftExpression, rightExpression);
    
                predicateBody = predicateBody == null
                     ? expression
                     : Expression.OrElse(predicateBody, expression);