我在 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 操作系统上的问题的详分割步说明:
下载fossil并将 fossil.exe 提取到您的
<working>
目录打开一个普通的命令提示符
运行
cd <working>
运行
fossil clone https://system.data.sqlite.org/ sds.fossil
运行
fossil open sds.fossil
运行
fossil update <release-tag>
例如,
fossil update release-1.0.105.2
更新
.\System.Data.SQLite.Linq\SQL Generation\SqlGenerator.cs
:
一个。取消注释行 1978 - 1983
b.用以下行替换第 1982 行:aggregateResult.Append("COUNT");
运行
cd Setup
运行
set_YYYY.bat
例如,要构建 net451 二进制文件,请运行
set_2013.bat
运行
build.bat ReleaseManagedOnly
删除对
System.Data.SQLite.Linq
的引用和System.Data.SQLite.EF6
来自 ASP.NET Web 项目添加对新
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/