异常ADO.NET代码的解释说明

开发 后端
本文向大家介绍ADO.NET代码,可能好多人还不了解ADO.NET代码,没有关系,看完本文你肯定有不少收获,希望本文能教会你更多东西。

 随着时代的进步科技的发展ADO.NET代码 版本也快速的提升与升级,下面我就对升级前和升级后的ADO.NET代码,做一下自己的解析。希望能够对大家有帮助,下面就进行解释说明。

最近在用ADO.NET代码操作数据时发现有很多都不能用上,前几天也发现一些但没有记下来,今天又出现了,我决定在博客园里把它记下来。这些功能 在LINQ TO SQL中可以用但在ADO.NET ENTITY FRAMEWORK 中确不能用。

今天在用到模糊查询时有用到  in模式的查询时突然出现异常代码如下:

  1. int[] intArray = {1,2,3,4,5,6,7,8,9,10,11,12,13,14 };  
  2. var query = from a in  AdonetContext.Products //Products 为实体类(表名)  
  3. where intArray.Contains(a.FID)  
  4. select a;  
  5. IEnumable<Product> lists=query.ToList();  

当执行到query.ToList()时(因为是延迟执行所以会在ToList方法时才直正执行查询)出现异常:

 LINQ to Entities does not recognize the method 'Boolean Contains[Int32](System.Collections.Generic.IEnumerable`1[System.Int32], Int32)' method, and this method cannot be translated into a store expression#t#

而 这句话如果用ADO.NET代码的话则可以正确执行最近生成的SQL语句为:

  1. exec sp_executesql N'SELECT [t0].[FID], [t0].[FProName], [t0].[FManufacturer], [t0].[FCategory], [t0].[FProDate], [t0].[FPrice]  
  2. FROM [dbo].[Products] AS [t0]  
  3. WHERE [t0].[FID] IN (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12, @p13)  
  4. ORDER BY [t0].[FID] DESC',N'@p0 int,@p1 int,@p2 int,@p3 int,@p4 int,@p5 int,@p6 int,@p7 int,@p8 int,@p9 int,@p10 int,@p11 int,@p12 int,@p13   
  5. int',@p0=1,@p1=2,@p2=3,@p3=4,@p4=5,@p5=6,@p6=7,@p7=8,@p8=9,@p9=10,@p10=11,@p11=12,@p12=13,@p13=14 

 

责任编辑:chenqingxiang 来源: 网易博客
相关推荐

2009-12-22 14:52:54

ADO.NET脚本

2009-12-23 15:13:15

Ado.Net Syb

2009-12-18 14:01:07

ADO.NET体系结构

2009-12-21 11:29:13

Ado.Net代码

2009-12-23 17:39:16

ADO.NET解决方案

2009-12-30 15:17:06

ADO.NET选项

2010-01-05 10:30:28

ADO.NET数据库连

2009-12-30 16:05:20

ADO.NET实例

2009-12-24 09:34:47

调用ADO.NET

2009-12-22 17:43:26

ADO.Net技术

2009-12-21 17:29:43

ADO.NET模型

2009-12-22 11:17:58

ADO.NET产品

2009-12-21 10:37:05

Ado.Net 实例

2009-12-21 14:55:49

ADO.NET对象

2009-12-31 14:18:46

ADO.NET类库

2009-12-21 14:55:49

ADO.NET属性

2009-12-18 17:01:21

ADO.NET数据

2009-12-30 15:11:35

ADO.NET数据

2010-01-04 13:16:31

ADO.NET命令

2009-12-22 09:15:02

ADO.NET功能
点赞
收藏

51CTO技术栈公众号