如何在 SQLite/NHibernate 组合中正确映射小型二进制对象(错误的类型关联)?
尝试在 SQLite
中存储 C#/.NET 类型 byte[]
的属性。这是我的映射:
<class name="MyClass" lazy="false" table="MyTable">
<property name="MyProperty" type ="BinaryBlob" access="property" />
</class>
在 SQL server
中,即使映射中没有显式 type="BinaryBlob"
,它也能像魅力一样工作。在 SQLite 中,我尝试了 SQL CREATE TABLE 语句和 NHibernate 数据类型之间的各种类型组合,但每次都会遇到以下异常: “无法编译映射”(由于类型不兼容)或无法从获取的数据类型强制转换为映射类型的异常。
insert 语句中 MyProperty
的值如下所示:0x7C87541FD3F3EF5016E12D411900C87A6046A8E8
。
更新:继续调试System.Data.SQLite.SQLiteDataReader
- 看起来无论SQL类型是什么(尝试decimal
,blob
、unsigned big int
) - 类型亲和力始终为text
。
请问我做错了什么(无论是技术上还是一般情况下)?欢迎任何建议。
Trying to store property of C#/.NET type byte[]
in SQLite
. Here is my mapping:
<class name="MyClass" lazy="false" table="MyTable">
<property name="MyProperty" type ="BinaryBlob" access="property" />
</class>
In SQL server
it works like a charm even without the explicit type="BinaryBlob"
in the mapping. In SQLite
I've tried various types' combinations between SQL CREATE TABLE
statements and in NHibernate
data types, but each time getting either an exception that "the mapping can't be compiled" (because of type incompatibility) or an exception that a cast from the fetched datatype to the mapping type is impossible.
The value of MyProperty
in insert statement looks like this: 0x7C87541FD3F3EF5016E12D411900C87A6046A8E8
.
Update: continuing to debug System.Data.SQLite.SQLiteDataReader
- looks like no matter what SQL type is (tried decimal
, blob
, unsigned big int
) - the type affinity is always text
.
What am I doing wrong, please (either technically or in general)? Any suggestion is welcomed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
text
关联性的原因是数据是从 CSV (逗号分隔值) 导入到表中的文件。使用正确的INSERT
语句切换到 SQL 文件解决了该问题。The reason for
text
affinity was that the data was imported into a table from CSV (comma-separated values) file. Switching to the SQL file with a properINSERT
statement solved the problem.