zoukankan      html  css  js  c++  java
  • EF中Entity SQL用法

     public List<policecase> GetPoliceCaseList(PoliceCaseFilter view)
            {
                string sqlString = "SELECT value pc FROM Entities.policecase AS pc";
                var where = "";
                if (!string.IsNullOrWhiteSpace(view.CaseAddress))
                {
                    //警情地址
                    if (where != "")
                    {
                        where += " and pc.[警情地址]  like '%" + view.CaseAddress + "%'";
                    }
                    else
                    {
                        where += " where pc.[警情地址]  like '%" + view.CaseAddress + "%'";
                    }             
                }
                if (!string.IsNullOrWhiteSpace(view.CaseType))
                {
                    //警情类别
                    if (where != "")
                    {
                        where += " and pc.[警情类别] like '%" + view.CaseType + "%'";
                    }
                    else
                    {
                        where += " where pc.[警情类别] like '%" + view.CaseType + "%'";
                    }
                }
                if (!string.IsNullOrWhiteSpace(view.StartTime))
                {              
                    //报警时间
                    if (where != "")
                    {
                        where += " and pc.[报警时间] >=datetime'" + Convert.ToDateTime(view.StartTime).ToString("yyyy-MM-dd HH:mm:ss") + "'";
                    }
                    else
                    {
                        where += " where pc.[报警时间] >=datetime'" + Convert.ToDateTime(view.StartTime).ToString("yyyy-MM-dd HH:mm:ss") + "'";
                    }
                }
                if (!string.IsNullOrWhiteSpace(view.EndTime))
                {
                    //报警时间
                    if (where != "")
                    {
                        where += " and pc.[报警时间] <=datetime'" + Convert.ToDateTime(view.EndTime).ToString("yyyy-MM-dd HH:mm:ss") + "'";
                    }
                    else
                    {
                        where += " where pc.[报警时间] <=datetime'" + Convert.ToDateTime(view.EndTime).ToString("yyyy-MM-dd HH:mm:ss") + "'";
                    }
                }
                if (!string.IsNullOrWhiteSpace(view.PoliceStation))
                {
                    //所属分局
                    if (where != "")
                    {
                        where += " and pc.[所属分局] like '%" + view.PoliceStation + "%'";
                    }
                    else
                    {
                        where += " where pc.[所属分局] like '%" + view.PoliceStation + "%'";
                    }
                }
                if (!string.IsNullOrWhiteSpace(view.RptType))
                {
                    //报警类型
                    if (where != "")
                    {
                        where += " and pc.[报警类型] like '%" + view.RptType + "%'";
                    }
                    else
                    {
                        where += " where pc.[报警类型] like '%" + view.RptType + "%'";
                    }
                }

                sqlString += where;

                var objctx = (Repository as IObjectContextAdapter).ObjectContext;
                ObjectQuery<policecase> pc = objctx.CreateQuery<policecase>(sqlString);

                var data = pc.ToList();

                return data;
            }
        }

  • 相关阅读:
    java构造简易的FIFO缓冲淘汰方法
    Could not parse multipart servlet request; nested exception is java.io.IOException: The temporary up
    nested exception is java.io.IOException: The temporary upload location
    springboot临时文件存储目录配置
    SpringBoot上传文件报错,临时路径不存在
    SpringBoot: 浅谈文件上传和访问的坑 (MultiPartFile)
    java并发-原子性
    用ATOMICSTAMPEDREFERENCE解决ABA问题
    【APP接口开发】chrome浏览器DHC工具安装使用(亲测有效)
    【Redis】windows环境下安装redis服务器,并配置php的redis扩展
  • 原文地址:https://www.cnblogs.com/jf-guo/p/6411421.html
Copyright © 2011-2022 走看看