使用LINQ语句 [英] Using LINQ Statements

查看:90
本文介绍了使用LINQ语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

db.table.where(c=>c.field1==value)



我有几个过滤表的条件,并通过复选框定义每个条件
例如checkbox1必须启用field1 = value,checkbox2必须启用
field2 = value等.

我如何将它们作为参数发送到where()?

我可以通过if和case和
解决3个条件和3个复选框的问题 考虑多个状态,但条件和复选框超过3个
需要更多行和where语句.



I have a several criteria for filtering table and define each by checkbox
for example checkbox1 must enable field1=value, checkbox2 must enable
field2=value and so on.

How i send them as parameters to where()?

i can solve this for 3 criteria and 3 checkbox by if and case and
considering multiple status but when criteria and checkboxes is more than 3
need to more lines and where statements.

How can do this by one where statement via parameters?

推荐答案

如果逻辑在您的where条件中有所不同,则一种可能是您创建了一种新方法来选择正确的行.在该方法中,如果符合条件,则返回该行.例如,请参阅:编写自定义LINQ扩展方法 [
If the logic varies in your where condition, one possibility could be that you create a new method for selecting the correct rows. In that method you return the row if it matches your conditions. For example, see: Writing Custom LINQ Extension Methods[^]


这篇关于使用LINQ语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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