FK Overrided by NULL Value
Issue #98
new
the the ForeignKey for a many-to-one relationship which is defined in the many end of the relationship is Overrided with Null after a second UpdateWithChildren():
- First Insertion Correct
- Second Insertion (same values) : Insertion Success but ForeignKey Goes NULL
- Third Data handling : database holds 4 rows with 2 foreign keys NULL and 2 others correct
- Fourth Data handling : the 4 rows in the database have a NULL FK (By data handling I mean executing the same code per each button click ..Example )
let's get to the code :
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 and data handling
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);