惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
博客园_首页
罗磊的独立博客
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
Last Week in AI
Last Week in AI
D
DataBreaches.Net
Jina AI
Jina AI
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
V
V2EX
D
Docker
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
H
Help Net Security
T
The Blog of Author Tim Ferriss

博客园 - yiyanxiyin

一个linq左连接查询速度问题 利用vba实现excel表格连接打印编号(一页两个编号),编号支持前缀 中断工作流并持久化到数据库中【源码】 按模板生成word报表,可扩展,demo可生成多页 在非asp.net程序中使用缓存 固定table的行列 固定table的cell宽度,多余的文字隐藏 - yiyanxiyin - 博客园 wcf中异步与双向通讯的区别 解决msmq私有队列不能持久保存的问题 sqlserver中使用查询分析器的一点小技巧 原创:一个相当有用的宏(for vs.net),该宏能大大的提高开发速度 Response.Redirect()与Server.Transfer()的区别 cellIndex在隐藏td中的问题,bug?(ie6) - yiyanxiyin - 博客园 一个format格式问题 - yiyanxiyin - 博客园 参透js 搞不懂的js 个人作品:全文搜索Access中的数据(附.net源代码) 个人作品:存储过程代码生成器(for MS SQL Server) 原创技术文章:保存帐号信息通用类(使用Session或者Cookie)
使用反射让linq实现动态查询, 类似拼接sql语句的where 条件
yiyanxiyin · 2012-10-11 · via 博客园 - yiyanxiyin

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;


public class A
{
    public A(string arg)
    {
        field = arg;
    }
   
    public string field
    {
        get;
        set;
    }
}

public partial class test : System.Web.UI.Page
{

    //传入字段名称和字段值进行查询
    private void LinqDynamicQuery(string fieldname, string fieldvalue)
    {
        List<object> o = new List<object>();
        o.Add(new A("abcd"));
        o.Add(new A("abcd123"));
        o.Add(new A("abcd245"));
        o.Add(new A("3222bcd"));

        var qry = from p in o
                  where System.ComponentModel.TypeDescriptor.GetProperties(p)[fieldname].GetValue(p).ToString().Contains(fieldvalue)
                  select p;
        System.Diagnostics.Debug.Assert(false, qry.Count().ToString());
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        LinqDynamicQuery("field", "abc");
    }
}