zoukankan      html  css  js  c++  java
  • Linq多条件查询

    1.

     public IEnumerable<M_Student> ReadCollegeAndName(String collnum, String name)
            {
                return from s in dc.M_Student
                       where
                          (!String.IsNullOrEmpty(collnum) ? s.CollegeNum.Equals

                        (collnum) : true) &&
                        (!string.IsNullOrEmpty(name) ? s.Name.Contains

                        (name) : true)
                       select s;
            }

    2.利用Linq执行SQL,运用SQL强大的拼接功能

     public string GetSqlString()
            {
                string s = "1=1";
                if (title.Text!="")
                {
                    s += " && title like %" + title.Text + "%";
                }
                if (name.Text!="")
                {
                    s += " && name like %" + name.Text + "%";
                }
                return s;
            }

            public List<T> GetList()
            {
                var l = from a in _db.Plate
                        where GetSqlString()
                        select a;
                return l.ToList<T>();
            }

    3.推荐这个

  • 相关阅读:
    Maven进价:Maven构建系列文章
    mybatis.net insert 返回主键
    IIS限制ip访问
    mybatis学习资源
    MVC4发布到IIS,出现HTTP 错误 404.0
    ElasticSearch 7.4.2 Root mapping definition has unsupported parameters
    钉钉网页版全屏
    sudo go 找不到命令
    ubuntu安装navicat
    golang 自动下载所有依赖包
  • 原文地址:https://www.cnblogs.com/nanxiaoxiang/p/2625499.html
Copyright © 2011-2022 走看看