ef-code-first-mapping

EF Core - error with duplicated key while adding data with unique index

你。 提交于 2021-02-10 18:51:54
问题 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

It is possible to query a NotMapped property?

拥有回忆 提交于 2019-12-11 13:08:51
问题 i'm working with EF6 code first, and i used this answer to map a List<stirng> in my entitie. This is my class [Key] public string SubRubro { get; set; } [Column] private string SubrubrosAbarcados { get { return ListaEspecifica == null || !ListaEspecifica.Any() ? null : JsonConvert.SerializeObject(ListaEspecifica); } set { if (string.IsNullOrWhiteSpace(value)) ListaEspecifica.Clear(); else ListaEspecifica = JsonConvert.DeserializeObject<List<string>>(value); } } [NotMapped] public List<string>