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

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

问题描述

我将产品的数据库从另一个支持Guid的产品移植到SQLite。我们知道,SQLite不支持Guid。我已经从我的数据库(数据库第一)创建了一个实体框架6模型,我需要从C#构建一个查询,将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 Entity Framework提供程序如何处理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提供程序不会将代码中的文字Guids处理成正确的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:

Gets converted into the following 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天全站免登陆