AutoMapper / AutoMapper.Collection

AutoMapper support for updating existing collections by equivalency
MIT License
245 stars 59 forks source link

Insert Master with details #172

Closed Boretto closed 2 years ago

Boretto commented 2 years ago

Hello, Is it possible to insert an entity with child entities? I have an exception saying that it can't insert explicit value on identity (autoincrement) colum. These are my clases:

` public partial class Maestro { [Key] public int Id { get; set; } [StringLength(50)] public string Nombre { get; set; }

    [InverseProperty("IdNavigation")]
    public virtual Detalle Detalle { get; set; }
}
public partial class Detalle
{
    [Key]
    public int Id { get; set; }
    [StringLength(50)]
    public string Nombre { get; set; }
    public int MaestroId { get; set; }

    [ForeignKey("Id")]
    [InverseProperty("Detalle")]
    public virtual Maestro IdNavigation { get; set; }
}

And this is the json request: { "Id": 0, "Nombre": "MasterName1", "Detalle": { "Id": 0, "Nombre": "DetailName1", "MaestroId": 0 } }`

It would be great an example of .net 6 WebAPI controller with the most common cases of InsertOrUpdate with new or existing Master and new, existing or omited so deleted child entities.

If the example includes an equality comparer with throught key anotation would be awesome.

Thanks in advance.

lbargaoanu commented 2 years ago

I think this is better suited for StackOverflow.