我正在尝试使用 Dapper 查询一个如下所示的 Sqlite 表:
CREATE TABLE "Running" (
"Id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"MachineName" BLOB NOT NULL DEFAULT 'machine' UNIQUE,
"IsOnline" INTEGER DEFAULT 0,
"TimesRan" INTEGER DEFAULT 0,
"LoginDateTime" TEXT,
"LogoutDateTime" TEXT,
"ForceUpgrade" INTEGER NOT NULL DEFAULT 0,
"Version" TEXT
)
目前在该表中,我只有一条记录:
1
DESKTOP-KQT7CGC
0
1
2019-09-21 03:04:10.099067
2019-09-21 03:04:37.6825109
0
4.0.0
var data = await _globalConfig.Connection.GetStatusAsync();
public async Task<List<ApplicationInfoModel>> GetStatusAsync()
{
using (IDbConnection cnn = new SQLiteConnection(ConfigurationManager.GetLocalOrSharedConnectionString(), true))
{
var output = await cnn.QueryAsync<ApplicationInfoModel>("select * from Running", new DynamicParameters());
return output.ToList();
}
}
ApplicationInfoModel
看起来像这样:
public class ApplicationInfoModel
{
public int Id { get; set; }
public string MachineName { get; set; }
public bool IsOnline { get; set; }
public int TimesRan { get; set; }
public DateTime LoginDateTime { get; set; } = DateTime.Now;
public DateTime LogoutDateTime { get; set; }
public bool ForceUpgrade { get; set; }
public string Version { get; set; }
}
我收到一条System.Data.DataException
消息Error parsing column 1 (MachineName=System.Byte[] - Object)
。
这是调用堆栈:
at Dapper.SqlMapper.ThrowDataException(Exception ex, Int32 index, IDataReader reader, Object value) in C:\projects\dapper\Dapper\SqlMapper.cs:line 3633
at Dapper.SqlMapper.<QueryAsync>d__33`1.MoveNext() in C:\projects\dapper\Dapper\SqlMapper.Async.cs:line 439
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at SdeHelper.Library.Main.DataAccess.SQLiteConnector.<GetStatusAsync>d__11.MoveNext() in G:\Users\mdumi\GitRepos\sdehelper\SdeHelper.Library.Main\DataAccess\SQLiteConnector.cs:line 154
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at SdeHelper.WpfUI.Framework.Helpers.ApplicationManager.<StartApplication>d__3.MoveNext() in G:\Users\mdumi\GitRepos\sdehelper\SdeHelper.WpfUI.Framework\Helpers\ApplicationManager.cs:line 39
内部异常:
Message: Object must implement IConvertible.
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType)
有人可以帮我理解为什么要IConvertible
在模型上实现吗?
我试图IConvertible
只为MachineName
属性实现,但它仍然抛出相同的异常。