Не удается добавить миграцию в Entity framework code
У меня есть такой код
internal class Currency
{
public int Id { get; set; }
public string Name { get; set; }
public decimal BuyPrice { get; set; }
public decimal SellPrice { get; set; }
public bool IsCash { get; set; }
public int BankId { get; set; }
public Bank? Bank { get; set; }
public Currency(string name, decimal buyPrice, decimal sellPrice,bool isCash,Bank? Bank)
{
this.Name = name;
this.BuyPrice = buyPrice;
this.SellPrice = sellPrice;
this.Bank = Bank;
this.IsCash = isCash;
}
}
internal class Bank
{
public int Id { get; set; }
public string Name { get; set; }
public List<Currency> Currencies { get; set; } = new();
public Bank(string name)
{
this.Name = name;
}
}
При попытке добавить миграцию выдает ошибку
No suitable constructor was found for entity type 'Currency'. The following constructors had parameters that could not be bound to properties of the entity type: cannot bind 'Bank' in 'Currency(string name, decimal buyPrice, decimal sellPrice, bool isCash, Bank Bank)'.
Ошибка исчезает когда я добавляю пустой конструктор. Но тогда при выполнении программы выдает ошибку при сохранении изменении
SqlException: Cannot insert explicit value for identity column in table 'Banks' when IDENTITY_INSERT is set to OFF.