SQLite Int64 vs Int32 问题和 SubSonic ActiveRecord

标签 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 )

我的 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 代码隐藏中有一个查询,如下所示:
SqlQuery sqlsql = new Select()
  .From( "SamplerData" )
  .Where( "ActiveState" )
  .IsEqualTo( 1 );
List<SamplerDatum> sampAll = sqlsql .ExecuteTypedList<SamplerDatum>();

设置为显示 sqlsql 值的断点显示:
{SELECT * FROM `SamplerData` WHERE ActiveState = @0}

然后代码抛出:

{“'System.Int64' 类型的对象无法转换为'System.Int32' 类型。”}

Visual Studio 中的“查找”没有显示 Int64 转换发生的位置。我知道 SQLite 使用 Int64 作为标识列,但不知道为什么/如何在 Structs 将其设为 Int32 时 SubSonic 处理转换。

帮助?!

谢谢..

最佳答案

我们在最新版本中修复了这个问题 - SQLite.tt 文件没有正确地将整数 PK 转换为 long (int 64)。如果您在 Github 上获取最新信息,则应该可以解决。确保你从模板项目中抓取。

关于SQLite Int64 vs Int32 问题和 SubSonic ActiveRecord,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1334672/

相关文章:

java - 将 SQLite 日期整数转换为 Java 日期

sqlite - 如何在 Sqlite3 中引用 UTF-8 字符串文字

ruby-on-rails - rails 中单一形式的多个 child

亚音速聚集约束 ("Having")

.net - 在 .NET 中使用 MySQL GeoSpatial 数据类型

android - 从 fragment 中的 sqlite 动态设置复选框

android - 在android中使用sqlite插入字符串,其中包含单引号和双引号

ruby-on-rails - 如何锁定一组对象以进行操作?

sql - 如何根据 ActiveRecord 中的条件在每第 n 个项目中插入?

database - SubSonic 3.0 两个不同的数据库命名空间问题