Я начал работать над частью back-end для проекта, и в настоящее время я пытаюсь создать базу данных с использованием EF Core Code-First. , но я столкнулся с проблемой при попытке запустить миграцию (относится к каскад удалить ).
Прежде всего, я прикреплю ниже ERD для БД и классов , которые я создал в C#:
И соответствующие классы:
Account.cs
public class Account
{
public int Id { get; set; }
public string Email { get; set; }
public string ExternalAccountId { get; set; }
public int CustomerId { get; set; }
public Customer Customer { get; set; }
}
BillingAddress.cs
public class BillingAddress
{
public int Id { get; set; }
public string Address { get; set; }
public int CustomerId { get; set; }
public Customer Customer { get; set; }
public List<Payment> Payments { get; set; }
}
BillingDetail.cs
public class BillingDetail
{
public int Id { get; set; }
public int CreditCardNumber { get; set; }
public DateTime ExpirationDate { get; set; }
public short Cvv { get; set; }
public int CustomerId { get; set; }
public Customer Customer { get; set; }
public List<Payment> Payments { get; set; }
}
Customer.cs
public class Customer
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string PhoneNumber { get; set; }
public int Cnp { get; set; }
public Account Account { get; set; }
public List<BillingDetail> BillingDetails { get; set; }
public List<BillingAddress> BillingAddresses { get; set; }
public List<Rental> Rentals { get; set; }
}
Payment.cs
public class Payment
{
public int Id { get; set; }
public int RentalId { get; set; }
public Rental Rental { get; set; }
public int BillingDetailId { get; set; }
public BillingDetail BillingDetail { get; set; }
public int BillingAddressId { get; set; }
public BillingAddress BillingAddress { get; set; }
}
Rental.cs
public class Rental
{
public int Id { get; set; }
public DateTime PickupDate { get; set; }
public DateTime DropoffDate { get; set; }
public int CustomerId { get; set; }
public Customer Customer { get; set; }
public List<Payment> Payments { get; set; }
public List<RentalVehicle> RentalVehicles { get; set; }
}
RentalVehicle.cs
public class RentalVehicle
{
public int Id { get; set; }
public int RentalId { get; set; }
public Rental Rental { get; set; }
public int VehicleId { get; set; }
public Vehicle Vehicle { get; set; }
}
Vehicle.cs
public class Vehicle
{
public int Id { get; set; }
public string Model { get; set; }
public string Brand { get; set; }
public string Color { get; set; }
public short ManufactureYear { get; set; }
public string Vin { get; set; }
public int Mileage { get; set; }
public short Horsepower { get; set; }
public string GearBox { get; set; }
public byte EngineSize { get; set; }
public float Price { get; set; }
public byte NoDoors { get; set; }
public List<RentalVehicle> RentalVehicles { get; set; }
}
Я сгенерировал миграцию, и когда я пытаюсь ее запустить, я получаю следующие ошибки:
Introducing FOREIGN KEY constraint 'FK_Payments_BillingDetails_BillingDetailId' on table 'Payments' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Я нашел с ome исправлена для замены ReferentialAction.Cascade на ReferentialAction.NoAction для onDelete при миграции, но я не уверен, действительно ли я должен это делать и как это произойдет повлиять на эту вещь мое приложение в долгосрочной перспективе.
Что именно я должен сделать, чтобы это исправить, и что является лучшим опытом?