PetaPoco/SQLite 聚合日期错误的解决方法 [英] Workaround for PetaPoco / SQLite aggregate date bug
本文介绍了PetaPoco/SQLite 聚合日期错误的解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是创建 SQLite 数据库、将一些数据填充到表中然后尝试检索它的完整代码.如果日期时间列周围有聚合函数,PetaPoco 将抛出错误.
Here's complete code to create a SQLite database, fill some data into a table and then try to retrieve it. If there's an aggregate function around a datetime column, PetaPoco will throw an error.
using System;
using PetaPoco;
class Program
{
static void Main(string[] args)
{
bool filenew = false;
if (!System.IO.File.Exists(@"c:\temp\database.sq3"))
filenew = true;
System.Data.SQLite.SQLiteConnection sqltc = new System.Data.SQLite.SQLiteConnection("Data Source=" + @"c:\temp\database.sq3");
sqltc.Open();
PetaPoco.Database db = new Database(sqltc);
if (filenew)
db.Execute("create table test1 (ID_CHANNEL integer primary key autoincrement, dtfld DateTime null, name string)");
test1 t = new test1();
t.name = "No Date";
db.Insert(t);
t = new test1();
t.dtfld = DateTime.Now;
t.name = "with date";
db.Insert(t);
// SUCCESS:
test1 lt1 = db.First<test1>("select dtfld from test1 where ID_Channel = 2");
// FAILURE:
test1 lt2 = db.First<test1>("select max(dtfld) as dtfld from test1 where dtfld is not null");
}
[PetaPoco.TableName("test1")]
[PetaPoco.PrimaryKey("ID_Channel")]
public class test1
{
public long ID_Channel { get; set; }
public DateTime? dtfld { get; set; }
public string name { get; set; }
}
}
任何人都可以建议修复仍然意味着 POCO 对象包含日期时间,并且我仍然可以访问日期的最大值?
Can anybody suggest a fix that still means the POCO object contains a datetime, and I can still access the max of a date?
推荐答案
找到解决方案 - 切换到 NPoco.对上面的唯一更改是将PetaPoco"替换为NPoco".
Found a solution - switch to NPoco. The only change to above was to replace "PetaPoco" with "NPoco".
这篇关于PetaPoco/SQLite 聚合日期错误的解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文