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;
            }
        }

  • 相关阅读:
    ios-点击图片放大,背景变半透明
    为代码分段标识
    方法的标签_With携带
    使用json要导入什么包
    Json中不支持任何形式的注释,那我们要怎么解决呢
    JFinal中文件上传后会默认放置到WebContent的upload包下,但是tomcat会自动重启,当我们再次打开upload文件夹查看我们刚刚上传的文件时,发现上传的文件已经没有了。
    JFinal上传文件时用getFile()方法报错
    JFinal文件上传时直接使用getPara()去接受表单的数据接收到的数据一直是null?
    Freemarker全部文档和具体实例
    Eclipse安装Freemarker插件
  • 原文地址:https://www.cnblogs.com/jf-guo/p/6411421.html
Copyright © 2011-2022 走看看