EF Core - error with duplicated key while adding data with unique index
问题 I'm trying to add data to the database using EF Core, but I cannot overcome duplicate key error: Cannot insert duplicate key row in object 'dbo.Stocks' with unique index 'IX_Stocks_Name'. The duplicate key value is (stock1). I have entity Stock that has relation one-to-many with Transaction - one Stock can be related with many Transaction s. The problem doesn't occur only if there's no Stock with a given ID in the database - in that case I can add many Transaction s with the same StockID and