Good day, afternoon or evening, I'm doing a small test project by taking an inventory. I'm working on C # ASP.Net Core 2.0 I have the following classes: Inventory customers Suppliers Sales Products
I did the Update-Database and everything went normal, then I thought that just as I did inventory exits, I also had to make entries to it, so I created my Entradas model, which basically does the same as sales but instead of subtracting , add to the inventory, but at the time of making my Update-Database I get the following error: Introducing FOREIGN KEY constraint 'FK_Entries_Provider_ProviderId' on table 'Entries' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint or index. See previous errors.
These are my classes: PRODUCT CLASS:
public class Producto
{
[Required]
public int ProductoId { get; set; }
[Required]
[StringLength(50, ErrorMessage = "{0} debe tener una longitud de {1} caracteres.")]
public string ReferenciaFabrica { get; set; }
[Required]
[StringLength(50, ErrorMessage = "{0} debe tener una longitud de {1} caracteres.")]
public string ReferenciaLocal { get; set; }
[Required]
[DataType(DataType.Currency)]
public double PrecioCompra { get; set; }
[Required]
[DataType(DataType.Currency)]
public double PrecioVenta { get; set; }
public int MarcaId { get; set; }
public int ProveedorId { get; set; }
public int TipoFiltroId { get; set; }
public Marca Marca { get; set; }
public Proveedor Proveedor { get; set; }
public TipoFiltro TipoFiltro { get; set; }
public ICollection<Ventas> Ventas { get; set; }
public ICollection<Entradas> Entradas { get; set; }
}
PROVIDER CLASS
public class Proveedor
{
public int ProveedorId { get; set; }
[Required]
[RegularExpression(@"^[A-Z]+[a-zA-Z''-'\s]*$", ErrorMessage = "{0} solo puede contener caracteres")]
public string Nombre { get; set; }
[Required]
[RegularExpression(@"^[A-Z]+[a-zA-Z''-'\s]*$", ErrorMessage = "{0} solo puede contener caracteres")]
public string Apellidos { get; set; }
[Required]
[StringLength(30, ErrorMessage = "{0} debe tener una longitud de {1} caracteres.")]
public string Telefono { get; set; }
[Required]
[StringLength(70, ErrorMessage = "{0} debe tener una longitud de {1} caracteres.")]
public string Direccion { get; set; }
public ICollection<Producto> Producto { get; set; }
public ICollection<Entradas> Entradas { get; set; }
}
CLASS INPUTS:
public class Entradas
{
[Key]
[Required]
public int EntradaID { get; set; }
[Required]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
public DateTime FechaCompra { get; set; }
[Required]
public int Cantidad { get; set; }
public int ProductoId { get; set; }
public Producto Producto { get; set; }
public int ProveedorId { get; set; }
public Proveedor Proveedor { get; set; }
}
INVENTORY CLASS:
public class Inventario
{
[Required]
public int InventarioID { get; set; }
[Required]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
public DateTime FechaInventario { get; set; }
[Required]
public int Stock { get; set; }
[Required]
[StringLength(20, ErrorMessage = "{0} debe tener una longitud de {1} caracteres.")]
public string Ubicacion { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
public DateTime FechaSalida { get; set; }
public int ProductoId { get; set; }
public Producto Producto { get; set; }
}
I do not know what to do to update my database and start inserting data, I hope your help, thank you very much