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);
好的,所以我正在尝试在 Person 和 Color 之间建立多对多的关系。颜色表将预先填充静态数据。
现在的问题是,每当我执行“InsertWithChildrenAsync”命令时,它总是将新数据插入到颜色查找表中。有没有办法在不影响颜色表的情况下插入具有选定颜色的人员记录?