Closed MakisupaVT closed 2 years ago
Their is a similar problem with EF 6 where Id's are part of a Foreign Key but not primary key of the entity, so when removing them from parent it tries to Orphan the entity instead of deleting it, and that's what you are seeing here. Solution for EF 6 was make it part of the Primary Key and it would force delete instead of Orphan.
Not sure exactly why it's having this issue in EF Core but I'm guessing it's a similar configuration issue.
I'm trying to use AutoMapper.Collection to synchronize a one-to-many collection from my source to the database. Walking through the debugger and the actual work seems to be done successfully -- objects get added, updated, deleted like they should -- but when I get down to my SaveChanges call, it blows up on me with this:
The property 'Id' on entity type 'Collection' is part of a key and so cannot be modified or marked as modified. To change the principal of an existing entity with an identifying foreign key first delete the dependent and invoke 'SaveChanges' then associate the dependent with the new principal.
This is the same behavior I ran into when attempting to do what AutoMapper.Collection does on my own.
Is there any easy way around this?