<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相关的内容。 |