I have the following problem-About ~60 tables on SQL that some have foreign key to each other,primary key as identity had to change to something else with logic. It was replaced by triggers that checks what is the next number and change the primary key field (by sequence)Now this makes several problems on EF when trying to insert new identity:In order to update the foreign keys i must retrieve back the entity from DB because the primary key is not refreshing.When I add more than one entity, the EF throws exception that the primary key is not unique. (It receive the default value in my case 0 for int)The solution for 1 is good only if I have other unique fields that I can get the entity back from the DB.The best solution for 2 that I could come up with is using Detach entity after each insert.Both are not optimal, to say the least.Would glad to hear if there is any other solution / another approach instead of triggers.At this point i cannot change the structure of the tables on the database, just manipulations on the primary key field.Supplement:The auto generated ID's were abandoned to eliminate duplicates on this field, as these tables will run on several db's that are merged from time to time.
Trigger on primary key instead of identity
sql;entity framework