0

Xamarin を使用してアプリケーションを開発するために、SQLite-Net PCL を SQLite-Net 拡張機能と共に使用しています。

私は2つのクラスを持っており、次のようAB定義しています:

public class A
{

    [PrimaryKey, AutoIncrement]
    public int Id
    {
        get;
        set;
    }

    [Unique]
    public string Name
    {
        get;
        set;
    }

    [OneToMany(CascadeOperations = CascadeOperation.All)]
    public List<B> Sons
    {
        get;
        set;
    }

    public A(string name, List<B> sons)
    {
        Name = name;
        Sons = sons;
    }

}

public class B
{

    [PrimaryKey, AutoIncrement]
    public int Id
    {
        get;
        set;
    }

    [Unique]
    public string Name
    {
        get;
        set;
    }

    public string LastModified
    {
        get;
        set;
    }

    [ForeignKey(typeof(A))]
    public int FatherId
    {
        get;
        set;
    }

    [ManyToOne]
    public A Father
    {
        get;
        set;
    }

    public B()
    {
    }

    public B(string name)
    {
        Name = name;
    }

}

次の方法で挿入または置換を使用しようとしています。

        var sons1 = new List<B>
        {
            new B("uno"),
        };

        var a1 = new A("padre", sons1);

        var sons2 = new List<B>
        {
            new B("uno2"),
        };

        var a2 = new A("padre", sons2);

        using (var conn = DatabaseStore.GetConnection())
        {
            conn.DeleteAll<A>();
            conn.DeleteAll<B>();
        }

        using (var conn = DatabaseStore.GetConnection())
        {
            conn.InsertOrReplaceWithChildren(a1, true);
            conn.InsertOrReplaceWithChildren(a2, true);
        }

問題は、2 番目InsertOrReplaceWithChildrenConstraint例外をスローしていることです。これは、 の一意の制約を削除するとスローされませんA.NameInsertOrReplaceWithChildren一意の制約に違反した場合、オブジェクトを置き換えることは想定されていません か?

4

1 に答える 1