我正在为 XAMARIN Forms项目(PCL)使用 SQLiteNetExtension 。我面临的问题是,在第二个 _connectionToDB.UpdateWithChildren()之后,在关系的许多端定义的多对一关系的ForeignKey被覆盖为Null:
(通过数据处理,我的意思是每按一次按钮执行相同的代码..例子)
让我们来看看代码:
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; }
}
现在进行数据库和数据处理
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);