SQLite Entity Framework 6 提供程序如何处理 Guid? [英] How does the SQLite Entity Framework 6 provider handle Guids?

查看:15
本文介绍了SQLite Entity Framework 6 提供程序如何处理 Guid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我们产品的数据库从另一个支持 Guid 的产品移植到 SQLite.众所周知,SQLite 不支持 Guid.我已经从我的数据库(首先是数据库)创建了一个实体框架 6 模型,我需要从 C# 构建一个查询,将 Guid 与从代码传递的 Guid 进行比较.

I am porting our product's database to SQLite from another product that supported Guids. As we know, SQLite does not support Guids. I've got created an entity framework 6 model from my database (database first) and I need to build a query from C# that compares the Guid to one passed from the code.

问题是我找不到任何关于 SQLite 实体框架提供程序如何处理 Guid 的文档.网络搜索也没有发现任何对我有用的东西.只是关于在 SQLite 中使用实体框架的问题.

The thing is I can't find any documentation on how the SQLite Entity Framework provider handles Guids. A web search didn't find anything useful for me, either. Just questions about using Entity Framework with SQLite.

谁能告诉我文档,或者告诉我如何通过 EF6 模型在 SQLite 数据库中使用 Guid?

Can anybody point me to the documentation, or maybe tell me how to work with Guids in a SQLite database through an EF6 model?

推荐答案

我终于有了这个问题的答案.

I finally have an answer to this problem.

我的问题是 SQLite Entity Framework 6 提供程序不能正确地将代码中的文字 Guid 转换为 SQL.也就是形式的Linq表达式

My problem is that the SQLite Entity Framework 6 provider doesn't handle converting literal Guids in your code into SQL properly. That is, a Linq expression of the form

context.MyEntity.Where( x => x.GuidColumn == new Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") )

被转换成以下SQL:

SELECT GuidColumn, Column1, Column2, . . . Column n
FROM MyEntity AS Extent1
WHERE Extent1.GuidColumn = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

这是错误的,因为列中存储的值是一个字节数组.

This is wrong, since the value stored in the column is a byte array.

根据SQLite 网站上的这个问题报告,事实证明,SQLite 团队认为这是提供程序中的一个错误,他们正在努力在 1.0.95.0 版本中修复它.我不知道什么时候会发布,但至少他们认识到这是一个问题并会解决它.

According to this problem report on the SQLite site, it turns out that the SQLite team considers this to be a bug in the provider and they are working to fix it in release 1.0.95.0. I don't know when that will be released, but at least they recognize it as a problem and are going to fix it.

这篇关于SQLite Entity Framework 6 提供程序如何处理 Guid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆