易截截图软件、单文件、免安装、纯绿色、仅160KB

LINQ to Entities 实现sql 关键字"In"方式总结

在LINQ to Entities中没有办法再像 LINQ to SQL 中一样使用 Contains 的方法来实现sql "in" 关键字
下面代码在 LINQ to SQL 中可行 在LINQ to Entities却无法运行: 
var s = db.Account.Select(c => c.ID);
var ret =(from t in db.Profile
 where s.Contains(t.ID)
 select t).ToList();
替代方法1:使用方法Any
var ids=db.Account.Select(c => c.ID);
var ret = (from t in db.Profile where ids.Any(c=>c==t.UserID) select t).ToList();
使用方法Any替换法搞了好久都没法实现直接对数组Any,下列代码仍无法执行:
int[] ids = new int[]{10101,10005,10007};
var ret = (from t in db.Profile where ids.Any(c=>c==t.UserID) select t).ToList();
于是继续Goolge寻找第二种方法,在MSDN论坛上找一个构造Lambda语句的方法
替代方法2:构造Lambda语句
        private static Expression<Func<TElement, bool>> BuildWhereInExpression<TElement, TValue>(Expression<Func<TElement, TValue>> propertySelector, IEnumerable<TValue> values)
        {
            ParameterExpression p = propertySelector.Parameters.Single();
            if (!values.Any())
                return e => false;
            var equals = values.Select(value => (Expression)Expression.Equal(propertySelector.Body, Expression.Constant(value, typeof(TValue))));
            var body&


相关文档:

sql中CASE的用法

 
来源:SQL帮助文档
CASE
计算条件列表并返回多个可能结果表达式之一。
CASE 具有两种格式:
简单 CASE 函数将某个表达式与一组简单表达式进行比较以确定结果。
CASE 搜索函数计算一组布尔表达式以确定结果。
两种格式都支持可选的 ELSE 参数。
语法
简单 CASE 函数:
CASE input_expression
 &n ......

sql server高级查询


1)  统计各个系的学生信息
select count(Sname) 总人数,Sdept from Student group by Sdept
2)  查询信管系学生的最大年龄和最小年龄
select MAX(Sage) 最大年龄,MIN(Sage) 最小年龄 from Student where
Sdept='信管系'
3)  查询信管系最大年龄和最小年龄的学生的姓名
  select Sname from St ......

SQL时间函数

--日期转换参数,值得收藏
select CONVERT(varchar, getdate(), 120 )2004-09-12 11:06:08
select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')20040912110608
select CONVERT(varchar(12) , getdate(), 111 )2004/09/12
select CONVERT(varchar(12) , getdate(), 112 )20040912 ......

MS SQL 2005链接服务器连接远程ORACLE全过程

第一步:下载安装Oracle 10g Release 2 客户端软件,下载连接是:
http://download.oracle.com/otn/nt/oracle10g/10201/10201_database_win32.zip
下载后安装
 
 
 
第二步:下载安装Oracle ODAC,下载连接是:
http://download.oracle.com/otn/other/ole-oo4o/ODAC1020221.exe
 
第三步: 重启MS SQ ......

[Sql Server2008]树结构的递归算法

本文主要讲述三个内容:
1.如何创建hierarychyid的表,插入数据及基本递归查询。
2.介绍hierarchyid的10种专有函数。
3.介绍hierarchyid特有的深度优先索引(Depth-First Indexing)和广度优先索引(Breadth-First Indexing)
在上一节中
http://blog.csdn.net/tjvictor/archive/2009/07/30/4395677.aspx
我们已经演 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号