c# - SQLite 异常 : "no such function: BigCount" when using "count" calling OData service with EntityFramework provider

标签 c# entity-framework wcf sqlite odata

我在 SQLite 数据库上使用 EF5(使用 System.Data.SQLite 1.0.90.0)。实体通过 OData 服务公开

public sealed class MyService : DataService<MyEntities>

例如,当我从我的应用程序内部查询我的实体时,它工作正常

using (var ents = new MyEntities) 
{
    var count = ents.SomeEntity.Select(ent => ent).Count();
}

当我像这样从浏览器发送请求时

http://localhost:8737/MyService/SomeEntity

它也工作正常,它返回我的实体列表。

但是当我创建以下请求时

http://localhost:8737/MyService/SomeEntity/$count

我通过某些客户端应用程序的服务引用查询服务(并且我的查询包含 Count()),我得到一个异常

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SQLite.SQLiteException: SQL logic error or missing database
no such function: BigCount

我想当生成 SQL 请求时,它包含 SQLite 没有的聚合函数 BIGCOUNT。如果我将我的数据库提供程序更改为 SQL Server,那么一切都很好。我不知道我能做些什么来改变请求的生成方式。我试图切换到 Entity Framework 6 + System.Data.SQLite 1.0.94.0 但没有用。我试图坚持使用 EF5 并将 System.Data.SQLite 的版本更改为以前的版本,但没有任何改变。我唯一的不同是我的 earlier problem当我使用 EF6+SQLITE1.0.94.0 时被“解决”(在引号中因为我不会调用我不理解的解决方案)。

2014 年 12 月 23 日更新

我们通过检查 System.Data.SQLite 源解决了这个问题,找到错误使用“bigcount”关键字的地方,根据我们的需要修复它,然后重建库。

如前所述here BigCount 应该在除 SQL Server 之外的所有数据库中编译为 COUNT()。看起来 BigCount 只是编译成 BigCount 之类的。

重建图书馆本身就很棘手,因为我还只是小学生,所以我的团队负责人做了那部分,我不能说细节,我没有时间深入研究. 至少,这是一个你可以用来解决同样问题的方向。

最佳答案

我也遇到了错误SQL logic error or missing database\r\nno such function: BigCount以下是我用来更新代码以解决 Windows 操作系统上的问题的详分割步说明:

  1. 下载fossil并将 fossil.exe 提取到您的 <working>目录

  2. 打开一个普通的命令提示符

  3. 运行 cd <working>

  4. 运行 fossil clone https://system.data.sqlite.org/ sds.fossil

  5. 运行 fossil open sds.fossil

  6. 运行 fossil update <release-tag>

    例如,fossil update release-1.0.105.2

  7. 更新.\System.Data.SQLite.Linq\SQL Generation\SqlGenerator.cs :
    一个。取消注释行 1978 - 1983
    b.用以下行替换第 1982 行:

    aggregateResult.Append("COUNT");

  8. 运行 cd Setup

  9. 运行 set_YYYY.bat

    例如,要构建 net451 二进制文件,请运行 set_2013.bat

  10. 运行 build.bat ReleaseManagedOnly

  11. 删除对 System.Data.SQLite.Linq 的引用和 System.Data.SQLite.EF6来自 ASP.NET Web 项目

  12. 添加对新 System.Data.SQLite.Linq.dll 的引用和 System.Data.SQLite.EF6.dll来自 <working>\bin\2013\Release\bin在 ASP.NET Web 项目中

来源:

System.Data.SQLite Source Code
System.Data.SQLite Build Procedures
System.Data.SQLite Ticket UUID 76c2eaadc0297696b2c5fb10d41a22325f56f9b9

关于c# - SQLite 异常 : "no such function: BigCount" when using "count" calling OData service with EntityFramework provider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27216111/

相关文章:

iphone - 如何在 iOs 中使用 NetTcpBinding .NET webservice?

WCF 双工 TCP 通信错误

c# - 获取父页面名称

c# - 在 Controller 操作之前调用的 WebAPI 函数

c# - XML 序列化和继承

c# - Autofac - 内存泄漏

c# - CreateDatabaseConnection 方法的单元测试

c# - 如何在 Entity Framework 中使用条件进行快速 GroupBy 查询

entity-framework - 在 POCO 实体上保存 DateTime.MinValue 时出现 SqlDateTime 溢出错误

c# - 如何检查两个不同的 URL 是否指向同一个资源?