How to detect if an Entity added to DbContext? [duplicate]
-
04-07-2021 - |
Question
Possible Duplicate:
DBContext Added/Attached Event?
I'm using a custom ID-Generating
strategy in EF 5. I override the SaveChanges
method to detect added entities and set them ID
s. But the new entities's ID
is not accessible until calling SaveChanges
. I search SO and find some answers. Here and here. In the second link, @KVerwold
's answer shows a way to detect changes that seems works. But it has just one up-vote and not accepted. Can I use @KVerwold's suggested way? Do you think it may couse any error -logical or any? OR do you have any other suggestions please? Thanks in advance.
Solution
I suggest that unless there is a strong business requirement for custom Ids, you not implement them. I think there is just one up vote for the post you mention because not too many people are implementing custom id generation as it doesn't pass the smell test, in my opinion.