从Esent中的表中读取所有行

时间:2013-07-15 09:52:05

标签: esent

我是新来的,我已经阅读了一些示例代码并发现基于密钥读取行。 什么是从任何特定表中读取所有行的方法。 就像我们在sql中做的那样

  

"从Table_Name"

中选择*

2 个答案:

答案 0 :(得分:0)

EDB没有像在SQL中那样使用查询的选项。相反,您可以使用esent API提供的功能来访问数据库。最终它看起来像这样:

的CreateInstance
初始化
BeginSession
AttachDatabase
的openDatabase
OpenTable的
RetrieveColumns (这是您实际读取数据的地方)
...

当然,有许多功能和特性可以加速您的数据库事务。但是你必须处理下面提到的一个接口:

您可以尝试使用Microsoft提供的API。这里有相当详细的文档和免费提供:Extensible Storage Engine

或者您可以使用Managed Esent Interface,您可以使用Visual Studio轻松使用它:ESENT Managed Interop

答案 1 :(得分:0)

可扩展存储引擎 (ESE) 中没有查询处理器。这意味着没有任何组件可以将文本查询转换为代码。

在术语中,ESE 是一种索引顺序访问方法 (ISAM)。

这意味着如果您要查询客户:

SELECT FirstName, LastName FROM Customers
WHERE AccountNumber = 6191128

你必须:

  • 告诉它您想使用客户
  • 告诉它您想使用 IX_Customers_AccountNumber 索引
  • 告诉它您要对 6191128
  • 执行等式搜索
  • 迭代结果;将它们存储在内存中的某处
  • 现在您要使用 IX_Customers_FirstNameLastName 索引
  • 告诉它使用聚集索引
  • 遍历之前的所有结果
  • 对对象中的集群键值执行相等搜索
  • 迭代结果;将它们存储在内存中的某处

在伪代码中:

//Use the InvoiceDate index on invoices
db.SetCurrentIndex("IX_Invoices_InvoiceDate");
db.ClearSearchPredicate();
db.AddSearchPredicate(SEEK_GreaterOrEqual, "20170801");
db.AddSearchPredicate(SEEK_LessThen, "20180901");

//read matching primary keys into list
List<Guid> invoiceIDs = new List<Guid>();
IDataReader rdr = db.GetResults();
while (rdr.Read()) do
{
   invoiceIDs.Add(rdr.GetGUID("InvoiceGUID"));
}

//Now use the primary clustered key to read the invoice numbers, and customer IDs
db.SetCurrentIndex("PK_Invoices");
for (Guid invoiceID in invoiceIDs) do
{
    db.ClearSearchPredicate();
    db.AddSearchPrediate(SEEK_Equal, invoiceID);
    rdr = db.GetResults();
    if rdr.Read() then
    {
        //todo: store these in another list
        customerID = rdr.GetInt32("CustomerID");
        invoiceNumber = rdr.GetInt32("InvoiceNumber");
    }
}

//Now seek for customers by customerID
db.ClearSearchPredicate()
db.AddSearchPredicate(SEEK_Equal, customerID);
rdr = db.GetResults();
if rdr.Read() then
{
   String name = rdr.GetString("Name");
   String isActive = rdr.GetString("IsActive");
}
相关问题