SQLite Int64 vs Int32问题和亚音速ActiveRecord
我以为其他地方也有报道,但我现在看不到。总之,一个简单的v3查询有问题。使用SQLite ADO.NET提供程序1.0.65.0。我的表结构如下所示:SQLite Int64 vs Int32问题和亚音速ActiveRecord,sqlite,activerecord,subsonic,subsonic3,Sqlite,Activerecord,Subsonic,Subsonic3,我以为其他地方也有报道,但我现在看不到。总之,一个简单的v3查询有问题。使用SQLite ADO.NET提供程序1.0.65.0。我的表结构如下所示: CREATE TABLE "SamplerData" ("RowId" INT PRIMARY KEY NOT NULL ,"SampName" VARCHAR(128),"SampPurpose" VARCHAR(2048),"ActiveState" INTEGER NOT NULL DEFAULT 1 ) SqlQuery sqlsq
CREATE TABLE "SamplerData" ("RowId" INT PRIMARY KEY NOT NULL ,"SampName" VARCHAR(128),"SampPurpose" VARCHAR(2048),"ActiveState" INTEGER NOT NULL DEFAULT 1 )
SqlQuery sqlsql = new Select()
.From( "SamplerData" )
.Where( "ActiveState" )
.IsEqualTo( 1 );
List<SamplerDatum> sampAll = sqlsql .ExecuteTypedList<SamplerDatum>();
我的Structs1.cs文件中包含以下内容:
Columns.Add(new DatabaseColumn("RowId", this)
{
IsPrimaryKey = true,
DataType = DbType.Int32,
IsNullable = false,
AutoIncrement = false,
IsForeignKey = false
});
Columns.Add(new DatabaseColumn("SampName", this)
{
IsPrimaryKey = false,
DataType = DbType.AnsiString,
IsNullable = true,
AutoIncrement = false,
IsForeignKey = false
});
Columns.Add(new DatabaseColumn("SampPurpose", this)
{
IsPrimaryKey = false,
DataType = DbType.AnsiString,
IsNullable = true,
AutoIncrement = false,
IsForeignKey = false
});
Columns.Add(new DatabaseColumn("ActiveState", this)
{
IsPrimaryKey = false,
DataType = DbType.Int32,
IsNullable = false,
AutoIncrement = false,
IsForeignKey = false
});
我在WPF codebehind中有一个查询,如下所示:
CREATE TABLE "SamplerData" ("RowId" INT PRIMARY KEY NOT NULL ,"SampName" VARCHAR(128),"SampPurpose" VARCHAR(2048),"ActiveState" INTEGER NOT NULL DEFAULT 1 )
SqlQuery sqlsql = new Select()
.From( "SamplerData" )
.Where( "ActiveState" )
.IsEqualTo( 1 );
List<SamplerDatum> sampAll = sqlsql .ExecuteTypedList<SamplerDatum>();
然后,代码抛出:
{“System.Int64”类型的对象无法转换为“System.Int32”类型。}
VisualStudio中的“查找”没有显示Int64转换发生的位置。我理解SQLite使用Int64作为标识列,但不理解为什么/如何在结构将其转换为Int32时亚音速处理转换
救命啊
谢谢..我对亚音速不太了解,但是sqlite的ADO.NET客户端对所有整数列都使用int64。在不了解亚音速的情况下,这只是猜测,但您可能希望将DbType.Int32列更改为DbType.Int64
最有可能的情况是,查询实际上执行得很好,但返回值(最初以ADO.NET方式为非类型化)正在被解绑到一些亚音速数据结构中—它认为基于DbType.Int32语句的结构应该是32位整数。您无法将long解包为int(即,
(int)(object)(long)0
将引发异常),因此您需要告诉亚音速希望使用64位整数,因为SQLite将为您提供64位整数。我们在最新版本中解决了这一问题-SQLite.tt文件没有正确地将整数PK转换为long(int 64)。如果你在Github上获得了最新的信息,应该可以解决这个问题。确保从templates项目中抓取