快速业务通道

Entity Framework学习初级篇5--ObjectQuery查询及方法

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-05-22
<DbDataRecord> records = query1.Select("it.customerid,it.country");

foreach (DbDataRecord c in records)

{

Console.WriteLine("{0},{1}", c[0], c[1]);

}

Console.WriteLine(records.ToTraceString());

//SQL输出:

//SELECT TOP (10)

//1 AS [C1],

//[Extent1].[CustomerID] AS [CustomerID],

//[Extent1].[Country] AS [Country]

//FROM [dbo].[Customers] AS [Extent1]

//ORDER BY [Extent1].[CustomerID] ASC

}

l SelectValue

实例代码如下:

using (var edm = new NorthwindEntities())

{

string esql1 = "select value c from NorthwindEntities.Customers as c order by c.CustomerID limit 10";

ObjectQuery<Customers> query1 = edm.CreateQuery<Customers>(esql1);

ObjectQuery<string> records = query1.SelectValue<string>("it.customerid");

foreach (string c in records)

{

Console.WriteLine("{0}", c);

}

Console.WriteLine(records.ToTraceString());

//SQL输出:

//SELECT TOP (10)

//[Extent1].[CustomerID] AS [CustomerID]

//FROM [dbo].[Customers] AS [Extent1]

//ORDER BY [Extent1].[CustomerID] ASC

}

l Skip/Top

实例代码如下:

using (var edm = new NorthwindEntities())

{

string esql1 = "select value c from NorthwindEntities.Customers as c order by c.CustomerID ";

ObjectQuery<Customers> query1 = edm.CreateQuery<Customers>(esql1);

query1 = query1.Skip("it.customerid asc", "10");

query1 = query1.Top("10");

foreach (Customers c in query1)

{

Console.WriteLine("{0}", c.CustomerID);

}

Console.WriteLine(query1.ToTraceString());

//SQL输出:

//SELECT TOP (10)

//[Extent1].[CustomerID] AS [CustomerID]

//FROM [dbo].[Customers] AS [Extent1]

//ORDER BY [Extent1].[CustomerID] ASC

}

本节,简单的介绍一下与ObjectQuery查询相关的语法,我个人觉得查询写法比较多,需要在日常的编程中去发现,在这里就不一一复述了。下节,将介绍EntityClient相关的内容。

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号