相关疑难解决方法(0)

是否有使用Linq动态创建过滤器的模式?

是否有使用Linq动态创建过滤器的模式?

我需要在列表上创建自定义过滤,过去我只是动态创建SQL ...看起来这对Linq来说是不可能的.

linq .net-3.5 linq-to-sql

21
推荐指数
3
解决办法
2万
查看次数

LINQ中的动态where子句 - 在运行时可用列名

免责声明:我使用System.Linq.Expressions中的表达式解决了这个问题,但我仍然在寻找更好/更简单的方法.

考虑以下情况:

var query = 
    from c in db.Customers
    where (c.ContactFirstName.Contains("BlackListed") || 
           c.ContactLastName.Contains("BlackListed")  ||
           c.Address.Contains("BlackListed"))
    select c;
Run Code Online (Sandbox Code Playgroud)

需要根据列入黑名单的术语检查的列/属性仅在运行时可用.如何生成这个动态where子句?

另一个复杂因素是Queryable集合(上面的db.Customers)被输入到'Customer'基类的Queryable中(比如'Person'),因此不能选择编写c.Address.

.net dynamic-linq linq-to-sql

9
推荐指数
2
解决办法
3万
查看次数

标签 统计

linq-to-sql ×2

.net ×1

.net-3.5 ×1

dynamic-linq ×1

linq ×1