public class Person {
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
[ManyToMany(typeof(PersonColor), CascadeOperations = CascadeOperation.All)]
public List<Color> FavoriteColors { get; set; }
}
public class Color {
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
[ManyToMany(typeof(PersonColor))]
public List<Person> People { get; set; }
}
public class PersonColor {
[ForeignKey(typeof(Person))]
public int PersonId { get; set; }
[ForeignKey(typeof(Color))]
public int ColorId { get; set; }
}
...
var person = new Person() {
FirstName = "Adrian",
LastName = "Simbulan",
FavoriteColors = new List<Color>() {
new Color() {Name = "Red"},
new Color() {Name = "Green"}
}
};
await _db.InsertWithChildrenAsync(person);
Ok so i'm trying to establish a many to many relationship between Person and Color. The color table will be pre-populated with static data.
Now the problem is, whenever I execute the "InsertWithChildrenAsync" command, it always inserts new data into the Color lookup table. Is there a way to insert a Person record with selected colors with out affecting the Color table?