带有Any()的C#DynamicLinq where子句 [英] C# DynamicLinq where clause with Any()

查看:680
本文介绍了带有Any()的C#DynamicLinq where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用其中的字符串where子句运行动态linq:

I want to run dynamic linq with a string where clause like this:

query = db.Customers.Where("Categories.Any(Code == 'Retail')");

客户实体具有类别的集合

Customer entity has collection of categories

class Customer
{
    public List<Category> Categories {get;set;}
    ...
}

class Category
{
    public Guid Id {get;set;}
    public string Code {get;set;}
}

任何人都可以告诉我是否可以做这样的事情?

Can anyone please tell me is it possible to do something like this?

PS:我需要where子句是字符串.将在运行时生成where子句,因此,我不能使用Linq查询表达式.

PS: I need where clause be string. The where clause will be generated at runtime, for this reason I can't use Linq query expression.

我正在使用Telerik DataAccess.

I'm using Telerik DataAccess.

推荐答案

只要您遵循例如,字符串文字必须用双引号引起来:

For instance, string literals must be enclosed in double quotes:

query = db.Customers.Where("Categories.Any(Code == \"Retail\")");

这篇关于带有Any()的C#DynamicLinq where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆