我花了很多时间尝试在一个表中插入信息,该表具有在 windows phone 8.1 中创建的多对多关系。既然我可以将信息自动插入到中间表中呢?我正在使用 sqlite-net 来处理表之间的关系,它们是我的实体
[Table("Compra")]
public class Compra
{
[PrimaryKey, AutoIncrement]
//[ForeignKey(typeof(Detalle))]
public int Id_Compra { get; set; }
public DateTime Fecha { get; set; }
[ManyToMany(typeof(Detalle), CascadeOperations = CascadeOperation.All)]
List<Producto> Productos { get; set; }
}
[Table("Producto")]
public class Producto
{
[PrimaryKey, AutoIncrement]
//[ForeignKey(typeof(Detalle))]
public int Id_Producto { get; set; }
public string Nombre { get; set; }
public bool Comprado { get; set; }
[ManyToMany(typeof(Detalle), CascadeOperations = CascadeOperation.All )]
List<Compra> Compras { get; set; }
}
[Table("Detalle")]
public class Detalle
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[ForeignKey(typeof(Compra))]
public int Id_Compra { get; set; }
[ForeignKey(typeof(Producto))]
public int Id_Producto { get; set; }
}
添加产品的功能和代码如下
private async void addProducto()
{
Producto prod = new Producto();
prod.Nombre = tbNuevoProducto.Text;
prod.Comprado = false;
SQLiteAsyncConnection conn = new SQLiteAsyncConnection("CarroCompra.db");
conn.InsertAsync(prod);
}
使用 InsertWhithChildren 可以自动插入到中间表中,但我不能在应用程序中使用它。非常感谢有人在帮助自己,因为我尝试了 2 天,但我还没有看到任何互联网信息
我应该使用什么样的 sqlite 以及我应该使用哪个连接器 sqlite 和路径?
我需要在插入产品时将其自动插入表格详细信息中