LINQ 多条件写法
源代码:
string depAll = (ddl_dep1.SelectedValue == "") ? "" : ddl_dep1.SelectedValue + '%';
string dep = ddl_dep1.SelectedValue.Split('/')[].ToString();
string strSql_dep = "Select * from dep where DEP_CLASS=2 AND dep_all_code LIKE '" + depAll + "' AND dep_code in (SELECT DISTINCT DEP2 FROM depview WHERE dep3 in (SELECT dep_code FROM person_limits WHERE upper(account)='" + UserID.ToUpper() + "') OR dep2 in (SELECT dep_code FROM person_limits WHERE upper(account)='" + UserID.ToUpper() + "') )Order By LDAP";
if (Request["account"] == null)
{
strSql_dep = strSql_dep.Replace("SELECT dep_code FROM person_limits", "SELECT user_dep FROM users");
}
DataTable dt_dep2 = cOracle.ProduceData(strSql_dep);
DataTable dtCount = cOracle.ProduceData("SELECT COUNT(*) FROM depview WHERE dep3 in (SELECT dep_code FROM person_limits WHERE upper(account)='" + UserID + "') AND dep1='" + dep + "' UNION all SELECT COUNT(*) FROM depview d WHERE dep1='" + dep + "'");
}
if (dtCount.Rows.Count == )
{
if (dtCount.Rows[][].ToString() == dtCount.Rows[][].ToString())
{
ddl_dep2.Items.Add(new ListItem(base.GetLocalResourceObject("PleaseSelect").ToString(), ""));
}
}
foreach (DataRow dr in dt_dep2.Rows)
{
ddl_dep2.Items.Add(new ListItem(dr["DEP_NAME"].ToString().Trim(), dr["DEP_ALL_CODE"].ToString().Trim()));
}
重写为LINQ:
string strSql_dep = "Select * from dep where DEP_CLASS=2 AND dep_all_code LIKE '" + depAll + "' AND dep_code in (SELECT DISTINCT DEP2 FROM depview WHERE dep3 in (SELECT dep_code FROM person_limits WHERE upper(account)='" + UserID.ToUpper() + "') OR dep2 in (SELECT dep_code FROM person_limits WHERE upper(account)='" + UserID.ToUpper() + "') )Order By LDAP";
// Xudaxia:修改EF
depAll = (ddl_dep1.SelectedValue == "") ? "" : ddl_dep1.SelectedValue;
IPERSON_LIMITSRepository personLimRep = new PERSON_LIMITSRepository(DatabaseFactory.GetFactory());
IDEPVIEWRepository depViewRep = new DEPVIEWRepository(DatabaseFactory.GetFactory());
IDEPRepository depRepository = new DEPRepository(DatabaseFactory.GetFactory());
IEnumerable<string> dep_codes = from p in personLimRep.GetAll()
where p.ACCOUNT.ToUpper() == UserID.ToUpper()
select p.DEP_CODE;
IEnumerable<string> DEP2s = (from d in depViewRep.GetAll()
where dep_codes.Contains(d.DEP3) ||
dep_codes.Contains(d.DEP2)
select d.DEP2).Distinct();
var query = from d in depRepository.GetAll()
where d.DEP_CLASS == &&
d.DEP_ALL_CODE.StartsWith(depAll) &&
DEP2s.Contains(d.DEP_CODE)
select d; if (Request["account"] == null)
{
strSql_dep = strSql_dep.Replace("SELECT dep_code FROM person_limits", "SELECT user_dep FROM users");
// Xudaxia:修改EF
IUSERSRepository userRep = new USERSRepository(DatabaseFactory.GetFactory());
dep_codes = from u in userRep.GetAll()
where u.ACCOUNT.ToUpper() == UserID.ToUpper()
select u.USER_DEP;
DEP2s = (from d in depViewRep.GetAll()
where dep_codes.Contains(d.DEP3) ||
dep_codes.Contains(d.DEP2)
select d.DEP2).Distinct();
query = from d in depRepository.GetAll()
where d.DEP_CLASS == &&
d.DEP_ALL_CODE.StartsWith(depAll) &&
DEP2s.Contains(d.DEP_CODE)
select d;
}
//DataTable dt_dep2 = cOracle.ProduceData(strSql_dep);
// Xudaxia:修改EF
DataTable dt_dep2 = query.ToDataTable();
//DataTable dtCount = cOracle.ProduceData("SELECT COUNT(*) FROM depview WHERE dep3 in (SELECT dep_code FROM person_limits WHERE upper(account)='" + UserID + "') AND dep1='" + dep + "' UNION all SELECT COUNT(*) FROM depview d WHERE dep1='" + dep + "'"); dep_codes = from p in personLimRep.GetAll()
where p.ACCOUNT.ToUpper() == UserID
select p.DEP_CODE;
int count1 = (from d in depViewRep.GetAll()
where dep_codes.Contains(d.DEP3) &&
d.DEP1 == dep
select d).Count();
int count2 = depViewRep.GetMany(d => d.DEP1 == dep).Count();
//if (dtCount.Rows.Count == 2)
//{
// if (dtCount.Rows[0][0].ToString() == dtCount.Rows[1][0].ToString())
// {
// ddl_dep2.Items.Add(new ListItem(base.GetLocalResourceObject("PleaseSelect").ToString(), ""));
// }
//}
if (count1 == count2)
{
ddl_dep2.Items.Add(new ListItem(base.GetLocalResourceObject("PleaseSelect").ToString(), ""));
}
foreach (DataRow dr in dt_dep2.Rows)
{
ddl_dep2.Items.Add(new ListItem(dr["DEP_NAME"].ToString().Trim(), dr["DEP_ALL_CODE"].ToString().Trim()));
}
LINQ 多条件写法的更多相关文章
- 白话LINQ系列2---以代码演进方式学习LINQ必备条件
今天,我们通过一个简单的示例代码的演进过程,来学习LINQ必备条件:隐式类型局部变量:对象集合初始化器:委托:匿名函数:lambda表达式:扩展方法:匿名类型.废话不多说,我们直接进入主题. 一.实现 ...
- 学习LINQ必备条件
转自:http://www.cnblogs.com/VolcanoCloud/p/4451302.html 学习LINQ必备条件:隐式类型局部变量:对象集合初始化器:委托:匿名函数:lambda表达式 ...
- EntityFramework linq 多条件查询,不定条件查询
一.场景描述: 开发的时候,有些查询功能,往往查询的条件是不确定的,用户没有填的不参与到查询中去. 如图1所示,用户可能只要给根据名称来查询即可,有时候开始时间和结束时间并不需要填写. 图 1 二.解 ...
- 转 --简单解决Linq多条件组合问题
本文笔者用清晰的实例,解决了Linq多条件问题,思路十分的清晰,笔者也很细心的做了描述,希望能给你带来帮助. 最近有个项目准备功能改版,师兄吩咐:尽可能地做到万般皆Linq,所以很多东西都要从存储过程 ...
- Linq动态条件
很多情况下,我们开发程序,需要动态拼接SQL查询语句; 比如 select top 1 * from User where age= 18 and name = 'renruiquan' 其中红 ...
- linq 多条件查询
Linq 进行多条件查询的时候使用PredicateBuilder帮助类可以很好的解决. 类的源码: public static class PredicateBuilder { /// <su ...
- LINQ多条件OR模糊查询
本文章转载:http://www.cnblogs.com/guyun/archive/2012/10/18/2729888.html 需求是这样的,有一张表tbl(Key[int],Value[str ...
- Linq查询条件里有可空字段比较时报错variable '<>h__TransparentIdentifier2' of type referenced from scope '', but it is not defined
当我运行下面的linq查询时报了这个错, 1: var result = (from so in svcContext.new_sales_orderSet 2: join soitem in s ...
- Linq in条件查询
Linq 实现sql中的not in和in条件查询 T-SQL的IN: Select ProductID, ProductName, CategoryID From dbo.Products Wh ...
随机推荐
- 【转】Xcode7.1环境下上架iOS App到AppStore 流程 -- 不错!!
原文网址:http://www.jianshu.com/p/a8bd16be122f 1.官网地址 Apple Developer 地址:https://developer.apple.com/mem ...
- DELL笔记本拆机添加内存条
在笔记本后面拧开7个螺丝 然后打开后盖 掰开卡口,内存条会弹出,此时按住内存条两侧的缺口往外用力就可以拔出内存条. 装入内存条时,先插入内存条,按下即可.
- Color the ball HDOJ--1556
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- [原]RobotFrameWork(四)变量运算与Evaluate
一.特殊变量运算: 执行结果: 二.Evaluate使用 函数释义:Evaluate是执行python表达式,并返回执行结果 示例1: 执行结果: 示例2: 执行结果: 作者:liuheng12345 ...
- Service Oriented Architecture and WCF 【转】
http://www.codeproject.com/Articles/515253/Service-Oriented-Architecture-and-WCF Introduction This a ...
- Spring框架整合Struts2
1,用Spring架构,及Struts2-spring-plugin插件 导入Spring的dist全部所需的jar包 Struts2的spring插件 struts2-spring-plugin.X ...
- DAL与数据库类型的对应关系
MSSQL Server类型 DbType类型 C#类型 MySql类型 DbType类型 C#类型 bit Boolean bool bit(1) Boolean bool tinyint ...
- hyperVisor
当前主要的hyperVisors:VMware vSphere.微软Hyper-V.Citrix XenServer .IBM PowerVM.Red Hat Enterprise Virtuliza ...
- Lattice Diamond安装
1.下载:到Lattice官网 http://www.latticesemi.com/ 注册一个lattice的账号后就可以去下载Diamond,登陆后如下图,根据自己系统情况选择对应的版本,我用的是 ...
- iOS全景
一张鱼眼图或者6方图,展现出来的全景影像效果图 PanoramaGL PanoramaGL是世界上第一个开源的实现360度全景图像的iOS.Android类库.基于OpenGL 支持球,立方体,圆柱. ...