如何使用简单的Odata过滤器比较List中的值?

时间:2015-04-23 09:44:28

标签: sql linq odata

如何编写将Mylist值与MyKeyTable值进行比较的过滤器?

我尝试过以下内容:

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();

因此output将包含键值匹配的所有值welcomehello

提前致谢。

1 个答案:

答案 0 :(得分:0)

完成后我尝试使用自定义表达式

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);