0

簡単なプロジェクトを作成しました。Sqlite と Sqlite エクステンソンを追加しました。ただし、テーブルを作成するとき。テーブルには Primary 関係も ForeignKey 関係も確立されていません。誰かが私が間違っていることを教えてもらえますか。

        SQLiteConnection connection = new SQLiteConnection("me4.db", SQLiteOpenFlags.Create | SQLiteOpenFlags.ReadWrite);
        connection.Execute("PRAGMA foreign_keys = ON");
        connection.Commit();

        connection.CreateTable<Group>();
        connection.CreateTable<UserGroup>();

ここに画像の説明を入力

[Table("group")]
public class Group
{
    public string DisplayName { get; set; }

    public string Descripton { get; set; }

    public bool IsPublic { get; set; }

    public string SmtpAddress { get; set; }

    [PrimaryKey]
    public string Id { get; set; }

}

[Table("usergroup")]
public class UserGroup
{
    public bool IsFavorite{ get; set; }

    public string LastVisitedTime { get; set; }

    [ForeignKey(typeof(Group),Unique=true)]
    public string Id { get; set; }
}
4

1 に答える 1

0

SQLite.Net は外部キーをサポートしていません。SQLite-Net 拡張機能は内部でIndexedプロパティを使用します。

主キーは期待どおりに機能しますが、データベース ブラウザに表示されない理由がわかりません。

それを確認するには、次のコードを試してください。

var group = new Group { Id = 1 };
connection.Insert(group); // Element inserted
connection.Insert(group); // ERROR: constrain violation
于 2015-12-07T10:10:52.473 に答える