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
计算条件列表并返回多个可能结果表达式之一。
CASE 具有两种格式:
简单 CASE 函数将某个表达式与一组简单表达式进行比较以确定结果。
CASE 搜索函数计算一组布尔表达式以确定结果。
两种格式都支持可选的 ELSE 参数。
语法
简单 CASE 函数:
CASE input_expression
&n ......
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 ......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BuildQuery
{
/// <summary>
/// 使用提供的数据建立一个SQL查询
/// </summary>
public class BuildQuery
{
#region 类的变量
int numFieldsCount, ......
PowerBuilder是目前最流行的数据库开发工具之一。PowerBuilder提供了在程序代码中加入嵌入式SQL语句的功能来支持对数据库的访问。但这种嵌入式SQL语句只能支持一些固定的标准的SQL语句,即在进行程序代码编译处理时这些SQL语句必须是确定的,例如:对哪张表哪几个字段进行操作在程序代码中是固定写明的,另外这种方式也不能 ......
第一步:下载安装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 ......