2012-05-13 20 views
0

異常我試圖用日期戳數據存儲在WP7上的本地數據庫。我按照MSDN Guidance和下面的代碼創建:WP7,本地數據庫,對鑄造datetime列

[Table] 
public class HistoricGame 
{ 
    [Column(IsDbGenerated = true, IsPrimaryKey = true)] 
    public int Id { get; set; } 

    [Column] 
    public DateTime DateStamp { get; set; } 

    [Column] 
    public string GameId { get; set; } 

    [Column] 
    public int Score { get; set; } 

    [Column] 
    public int LongestSequence { get; set; } 

} 

public class HistoricGameContext : DataContext 
{ 
    public const string ConnectionString = "Data Source=isostore:/NumbersNerdDB.sdf"; 

    public HistoricGameContext() 
     :base(ConnectionString) 
    {} 

    public Table<HistoricGame> HistoricGames 
    { 
     get { return GetTable<HistoricGame>(); } 
    } 
} 

這就是所謂的寫入數據庫:

private void StoreThisGame() 
{ 
    using (var db = new HistoricGameContext()) 
    { 
     if (!db.DatabaseExists()) 
      db.CreateDatabase(); 
     var game = new HistoricGame 
     { 
      DateStamp = DateTime.Now, 
      GameId = "1", 
      LongestSequence = _currentGame.LongestCorrectSequence, 
      Score = _currentGame.TotalPoints 
     }; 
     db.HistoricGames.InsertOnSubmit(game); 
     db.SubmitChanges(); //<- This is where it throws an InvalidCastException 
    }    
} 

然而db.SubmitChanges();保持與消息拋出InvalidCastException「無法從類型轉換「 System.DateTime'鍵入'System.Byte []'。「

我找不到任何指向數據庫相關問題的東西,雖然我使用的原始示例不包含DateTime,但Silverlightshow.net上的示例確實在非常相似的上下文中使用了DateTime。

我是不是看錯了地方或者是有什麼我失蹤?

+0

煩人,我現在已經測試了我的手機上,它似乎工作得很好。因爲我不會有任何測試版測試人員,所以不會令人滿意,不一定認爲它會在其他手機上工作,但它甚至不能在模擬器上工作。 – Hans

回答

0

我有類似的問題。

在我來說,這是缺少對我的桌子的財產「服務器數據類型」的值。儘管我將「Type」屬性定義爲DateTime,但這還不夠。