2017-05-09 11 views
1

Ich verwende SQLite in meinem UWP-Projekt. Meine Modellklasse hat Datetime-Felder:SQLite Bigint zu Datetime in C#

public class EducationInfo 
{ 
    [SQLite.Net.Attributes.PrimaryKey, SQLite.Net.Attributes.AutoIncrement] 
    public int educationInfoId { get; set; } 
    public String Education { get; set; } 
    public bool Enabled { get; set; } 
    public DateTime StartDate { get; set; } 
    public DateTime EndDate { get; set; } 
    public int UserId { get; set; } 

    // Not in the DB 
    [Ignore] 
    public string FormattedStartDate { get; set; } 
    [Ignore] 
    public string FormattedEndDate { get; set; } 

    public EducationInfo() 
    {} 

    public EducationInfo(String edu, bool enabled, DateTime st, DateTime ed, int userId) 
    { 
     this.Education = edu; 
     this.Enabled = enabled; 
     this.StartDate = st; 
     this.EndDate = ed; 
     this.UserId = userId; 
    } 

} 

Das Problem ist, dass SQLite die Datetime Felder als bigint erstellen. Wie kann ich diese Bigint lesen und als DateTime einstellen?

`

var education = connection.Table<EducationInfo>().Where(e => e.UserId == user.userID); 
         foreach(var edu in education) 
         { 
          EducationInfo educationInfo = new EducationInfo(); 
          educationInfo.StartDate = edu.StartDate; 
         } 

Der obige Code Fehler nicht zurück, aber das Datum Wert ist falsch. `

+0

Welche ORM verwenden Sie? – Dai

+0

Es ist SQLite.NET-PCL – user6824563

Antwort

2

ist hier eine Lösung zu Speicher als Datum- statt Bigint:

Der SQLiteConnection Konstruktor nimmt einen Parameter storeDateTimeAsTicks wahr der standardmäßig auf. Sie können das als false übergeben, wenn Sie einen DateTime-Typ anstelle von bigint verwenden möchten.

https://github.com/oysteinkrog/SQLite.Net-PCL/issues/203