LINQ的动态哪里算什么? [英] Linq dynamic where count?

查看:214
本文介绍了LINQ的动态哪里算什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在使用列表中。我想somethink是这样的:

Is it possible to use list in where. I want somethink like this:

public class Customer
{
    string FirtsName;
    string LastName;
    int Number;
    .....
}



我想用过滤客户复选框。如果我选择的名字和号码,然后将在其中生成条款

I want to filter customers with using checkboxes. If I select FirstName and Number then where clause will be generated

.where(x=> x.FirstName == "SomeFirstName" && x.Number == someNumber)

如果我只选择号码,然后where子句会生成

If I select only number then where clause will be generated

.where(x.Number == someNumber)

如果我选择的名字,姓氏和号码,然后将在其中生成条款

If I select FirstName, LastName and Number then where clause will be generated

.where(x=> x.FirstName == "SomeFirstName" && x.Number == someNumber && x.LastName == "LastName")

我的意思是,不仅动态列名,我也想生成where子句指望了。列名和值从名单出来:

I mean not only dynamic column names, also I want to generate where clauses count, too. Column names and values are came from list:

我希望,我可以解释。先谢谢了。

I hope, I can explain. Thanks in advance.

推荐答案

您可以给的动态LINQ 的一个尝试。有了这个,你可以写这样的:

You could give Dynamic LINQ a try. With this you could write something like:

var db = new NorthwindDataContext;
var query = db.Products.Where("CategoryID=2 And UnitPrice>3").OrderBy("SupplierId");

这篇关于LINQ的动态哪里算什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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