你能说出为什么 DapperExtensions Update 方法执行失败吗?

Can you tell why DapperExtension''s Update method is failing to execute?

我正在使用 SQLite、Dapper 和 DapperExtensions,所有这些都是通过 NuGet 最新的。

这是我的 table 的架构...

CREATE TABLE `LibraryInfo` (
    `Id`    INTEGER NOT NULL,
    `Name`  TEXT NOT NULL CHECK(length ( Name ) > 0),
    `Description`   TEXT,
    `Version`   TEXT NOT NULL CHECK(length ( Version ) > 0),
    PRIMARY KEY(Id)
);

其中有一行包含以下数据

Id = "0"
Name = "Test Library"
Description = "This is the Test Library"
Version = "1.2.3.4"

这是我的 POCO table...

public class LibraryInfo
{
    public int    Id          { get; set; }
    public string Name        { get; set; }
    public string Description { get; set; }
    public string Version     { get; set; }
}

这是我初始化 DapperExtensions 的方法(我的 table 是复数 除了 对于这个 table)...

DapperExtensions.DapperExtensions.DefaultMapper = typeof(PluralizedAutoClassMapper<>);

public class LibraryInfoMapper : ClassMapper<LibraryInfo>
{
    public LibraryInfoMapper()
    {
        Table(nameof(LibraryInfo));
        AutoMap();
    }
}

这是让我从数据库中读取 ID 为 0 的单行的代码...

var libraryInfo = connection.Get<LibraryInfo>(0);

效果很好。然而,这失败了...

libraryInfo.Description = "Test";
connection.Update(libraryInfo);

例外情况...

System.Data.SQLite.SQLiteException occurred ErrorCode=1 HResult=-2147467259 Message=SQL logic error or missing database near ".": syntax error Source=System.Data.SQLite StackTrace: at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain) InnerException:

不知道为什么!试图弄清楚如何查看 SQL 它生成的内容,但我不知道该怎么做,甚至不知道该怎么做。

求助!!!

问题是 DapperExtensions 中 SQL 生成的默认方言是 SqlServer,这意味着内部生成的 SQL 是使用 table 别名创建的,Sqlite 不支持。在发出任何命令之前,您需要将 Dapper Extensions SQL 方言更改为 Sqlite:

DapperExtensions.DapperExtensions.SqlDialect = new DapperExtensions.Sql.SqliteDialect();

更改后,Dapper Extensions 将创建 SQL Sqlite 格式的命令。