簡體   English   中英

WinRT的多個SQLite主鍵?

[英]SQLite for WinRT multiple primary keys?

有沒有一種方法可以在SQLite中為c#使用注釋組合鍵? 以下代碼引發異常,表明該表具有多個主鍵:

userDatabase.CreateTable<MyObject>();

//class file
[SQLite.Table("MyObject")]
public class MyObject
{
    [SQLite.PrimaryKey]
    public int IdOne { get; set; }

    [SQLite.PrimaryKey]
    public int IdTwo { get; set; }
}

不,當前代碼庫無法實現,但是有幾個請求請求將其修復為https://github.com/praeclarum/sqlite-net/pull/281

我有解決辦法。 這不是最佳解決方案,但對我有用。

這個想法是手動制作組合鍵。 因此,在您的情況下,請聲明:

userDatabase.CreateTable<MyObject>();

//class file
[SQLite.Table("MyObject")]
public class MyObject
{
    public int IdOne { get; set; }
    public int IdTwo { get; set; }

    [SQLite.PrimaryKey]
    public string auxCompositeKey {get; set;}
}

然后,在創建對象時,只需按如下所示制作de auxCompositeKey:

oMyObject.auxCompositeKey = IdOne.ToString()+ IdTwo.ToString()。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM