1

XAMARIN Forms プロジェクト (PCL)にSQLiteNetExtensionを使用しています。私が直面している問題は、関係の多端で定義されている多対一の関係の ForeignKey が 2 番目の_connectionToDB.UpdateWithChildren()の後に Null でオーバーライドされることです:

  • 初挿入正解
  • 2 回目の挿入 (同じ値): 挿入は成功するが、ForeignKey が NULL になる
  • 3 番目のデータ処理: データベースは、2 つの外部キーが NULL で、他の 2 つが正しい 4 つの行を保持します
  • 4 番目のデータ処理: データベースの 4 つの行には NULL FK があります

(データ処理とは、ボタンをクリックするたびに同じコードを実行することを意味します..例)

コードに行きましょう:

public class Bus
{
    [PrimaryKey, NotNull, Unique] //it's not AutoIncrement because it's unique 
    public String Id { get; set; }

    public string PlateNumber { get; set; }

    [OneToMany]
    public List<Person> Passengers { get; set; }
}

public class Person
{
    [PrimaryKey, NotNull, Unique]
    public int Id { get; set; }

    public string Name { get; set; }

    [ForeignKey(typeof(Bus))]
    public String BusId { get; set; }

    [ManyToOne]
    public Bus Bus { get; set; }
}

now DB とデータ処理

var Persons = new List<Person>();
Bus B10 = new Bus {Id = "15458 ghf 14" ; PlateNumber = "122541 tn 154";}
_connectionToDB.InsertOrReplace(B10);

Person P1 = new Person{Id=15547; Name= Robert };
_connectionToDB.InsertOrReplace(P1);
Persons.Add(P1);

Person P2 = new Order {Id=25547;Name= Katherina};
_connectionToDB.InsertOrReplace(P2);
Persons.Add(P2);

B10.Passengers = Persons ;
_connectionToDB.UpdateWithChildren(B10);
4

0 に答える 0