我想從SQLite中拉出最近的DateTime字段,它返回的時間不正確。LINQ to SQL查詢不返回正確DateTime
這裏的數據庫中的數據:
這裏是我的方法通過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();
}
}
的問題是,它沒有返回預期約會時間。我得到1/1/0001上午12點:
我在做什麼錯?
編輯:這是正在使用的提供者,每個請求:https://components.xamarin.com/view/sqlite-net
編輯2:請求SyncAudit類別:
class SyncAudit
{
public string Server { get; set; }
public string Database { get; set; }
public DateTime SyncTime { get; set; }
public int Successful { get; set; }
}
你的標題說 「的LINQ to SQL」 - 我想的LINQ to SQL只與SQL Server合作...你實際使用的LINQ提供者是什麼? –
你是否有任何與syntime作爲空行,因爲值來的是默認datetime.min值 – Sachu
它看起來像不正確的表或連接字符串。它找不到任何記錄並返回默認值。嘗試第一個,而不是FirstOrDefault,看看你是否得到像序列一樣的錯誤不包含元素或類似的東西.. –