I am using Entity Core 8 and I have a list of entities that I want to add to the database.
In this list, there could be entities that exist in the database, so if I add all the entities and try to save the changes, I could get an update exception.
Well, one solution could to get from the database the IDs of the entities that are in the list, add to the context the entities that not exist in the database and save the changes. This would work if no other process add and entity that still is in the list.
I could handle the exception, but if when I handle the exception another process add another entity, I would have the same problem.
Another option it would be to use pesimistic concurrency, but i would like to avoid this.
Another option it would be to use raw sql, and create a tsql that put each insert inside a try catch and igonre if there is some expcetion, or at last, a unique exception.
is there another option? What I would like to do it is try to add all the entities, and if there is some entity that exists in the database, ignore it and add the rest of the entities.
Thanks.