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&
相关文档:
系统环境:Windows 7
软件环境:Visual C++ 2008 SP1 +SQL Server 2005
本次目的:编写一个航空管理系统
这是数据库课程设计的成果,虽然成绩不佳,但是作为我用VC++ 以来编写的最大程序还是传到网上,以供参考。用VC++ 做数据库设计并不容易,但也不是不可能。以下是我的程序界面,后面 ......
SQL Server 查询
查询的时候应该尽量按照复合索引中的顺序来做条件查询;(比如IXC中spInterActiveInstance_GetByIDToStat条件and ProcessState<>99的位置);
如果在程序中有For或者是Foreach,在存储过程中又有IF Exists,那就要看是否可以在表中加入复合索引了,IF Not Exists可以转换为IF Exists来使用索引; ......
Microsoft SQL Server2005技术内幕:T-SQL程序设计
http://www.amazon.cn/mn/detailApp/ref=sr_1_25?_encoding=UTF8&s=books&qid=1261538877&asin=B0011C2568&sr=8-25
Microsoft SQL Server 2005技术内幕:查询、调整和优化
http://www.amazon.cn/mn/detailApp/ref=sr_1_4?_encoding=UTF8&s=books&am ......
学会数据库是很实用D~~记录一些常用的sql语句...有入门有提高有见都没见过的...好全...收藏下...
其实一般用的就是查询,插入,删除等语句而已....但学学存储过程是好事...以后数据方面的东西就不用在程序里搞喽..而且程序与数据库只要一个来回通讯就可以搞定所有数据的操作....
一、基础
1、说明:创建数据库
Create DAT ......
本文主要讲述三个内容:
1.如何创建hierarychyid的表,插入数据及基本递归查询。
2.介绍hierarchyid的10种专有函数。
3.介绍hierarchyid特有的深度优先索引(Depth-First Indexing)和广度优先索引(Breadth-First Indexing)
在上一节中
http://blog.csdn.net/tjvictor/archive/2009/07/30/4395677.aspx
我们已经演 ......