使用LINQ获取最新的datetime列

时间:2015-07-10 14:47:25

标签: c# linq

我有一个镜像SQLite表的简单类。

class SyncAudit
{
    public string Server { get; set; }
    public string Database { get; set; }
    public string SyncTime { get; set; }
    public int Successful { get; set; }
}

我试图构建一个返回最近同步时间的LINQ方法。

    public string getLastSyncTime()
    {
        using (var db = new SQLite.SQLiteConnection(this.DBPath))
        {
            var query = db.Table<SyncAudit>()
                .OrderByDescending(c => c.SyncTime)
                .Select(c => c.SyncTime)
                .FirstOrDefault();
            return query.ToString();
        }
    }

我试图在SQLite数据库中找到最新的同步时间并将其作为字符串返回。

我做错了什么?

编辑:我收到以下错误:

An exception of type 'System.MissingMethodException' occurred in mscorlib.dll but was not handled in user code

Additional information: No parameterless constructor defined for this object.

使用:https://components.xamarin.com/view/sqlite-net

1 个答案:

答案 0 :(得分:4)

<SampleMAIN> <Sample type="1"> <Sample_Batch>123 </Sample_Batch> <SampleMethod>1 </SampleMethod> </SampleMAIN> 是模型中的字符串,但似乎(或应该是)SyncTime。所以在数据库中修复它。如果那不可能,你必须解析它:

DateTime