Asked by:
Problem with update database

Question
-
User-2035378889 posted
Hell every one I have problem after changing on model
Introducing FOREIGN KEY constraint 'FK_dbo.PurchaseItems_dbo.Supplier_MedicineId' on table 'PurchaseItems' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify
here is my purchase model
using PharmaApp.Core.DataModel.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace PharmaApp.Core.DataModel
{
[Table("PurchaseItems")]
public class PurchaseItemsModel : BaseModel
{
[Required]
public double Price { get; set; }
[Required]
public int Quantity { get; set; }
[Required]
public double Amount { get; set; }[DisplayName("Products")]
[ForeignKey("SupplierModel")]
public int MedicineId { get; set; }
public SupplierModel SupplierModel { get; set; }
public int Bardanaweight { get; set; }
public int Bagweight { get; set; }
public int Muns { get; set; }
public int Deduction { get; set; }
public int Weight { get; set; }
public int Amount2 { get; set; }
public int Qty { get; set; }
public int Rate { get; set; }
public int Vouchervalue { get; set; }
public bool Incl { get; set; }
public string userName { get; set; }
public string Narration{ get; set; }
public string Drcr { get; set; }
//public string companyName { get; set; }
[DisplayName("Purcashe")]
[ForeignKey("PurchaseModel")]
public int PurcasheId { get; set; }
public PurchaseModel PurchaseModel { get; set; }
}
} and this is my Supplier modelusing PharmaApp.Core.DataModel.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace PharmaApp.Core.DataModel
{
[Table("Supplier")]
public class SupplierModel : BaseModel
{
[Required]
public string Name { get; set; }
public string Email { get; set; }
public string TrialCategory { get; set; }
public string AccountType { get; set; }
public string AccountSubType { get; set; }
public string PartyType { get; set; }
public string ItemType { get; set; }
public string Drcr { get; set; }
public new string Company { get; set; }
public int Bf { get; set; }
public DateTime BFDate { get; set; }
public string Phone { get; set; }
public string Address { get; set; }
public string Notes { get; set; }}
}due to a newcomer in mvc I could't understand where is my mistake
please some one help me
thank a lot
Sunday, February 28, 2021 5:10 PM
All replies
-
User1535942433 posted
Hi ABDULLAH ANOTECH,
According to your description,as far as I think,you could set only one ForeignKey and use nullable foreign key.
using PharmaApp.Core.DataModel.Base; using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PharmaApp.Core.DataModel { [Table("PurchaseItems")] public class PurchaseItemsModel : BaseModel { [Required] public double Price { get; set; } [Required] public int Quantity { get; set; } [Required] public double Amount { get; set; } [DisplayName("Products")] [ForeignKey("SupplierModel")] public int? MedicineId { get; set; } public SupplierModel SupplierModel { get; set; } public int Bardanaweight { get; set; } public int Bagweight { get; set; } public int Muns { get; set; } public int Deduction { get; set; } public int Weight { get; set; } public int Amount2 { get; set; } public int Qty { get; set; } public int Rate { get; set; } public int Vouchervalue { get; set; } public bool Incl { get; set; } public string userName { get; set; } public string Narration{ get; set; } public string Drcr { get; set; } //public string companyName { get; set; } [DisplayName("Purcashe")] } }
More details,you could refer to below article:
Best regards,
Yijing Sun
Monday, March 1, 2021 2:12 AM