-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EF Value Generator for int and long backed Id's #78
base: master
Are you sure you want to change the base?
Conversation
I like the idea behind this, but the implementation is a bit problematic, I think. Currently, it has race conditions as it's not thread safe. It also won't work in a server farm scenario (one of the reasons I'm not a fan of sequential IDs!).🤔 However, I'm not sure exactly how this is supposed to work? I'm a bit torn how to proceed, this would be very useful for e.g. the |
Status on this? Or is it abandoned? |
Hi @Rudde sorry no haven't abandon this from my end. Just had a few busy weekends :D
Been doing a bit more research into EF, seems it should be thread safe as long as each thread uses it own System.Threading.Interlocked.Increment(ref _id); Implement would then be similar to the internal EF Value generator which might be better. Internal Long Generator For the case of server farms, not sure if there would be an issue as the Generator only generates temporary values. The SQL Server is responsible for the final generated value, this value would be used by EF to know which entity it should assign the "real" ID back too.
For int/long it helps prevent the an issue where inserting multiple entity all have an internal value of Happy to add one for Guid as well, think the only difference would be that it wouldn't generate a temp value like the int/long ones. Though for Guid I found Hope this help @andrewlock |
Won't this still have a race condition if you run several API instances? Isn't it it best to let the database increment the value, like it does on regular ints, or isn't this possible to configure? I understand it probably will be slightly different for each underlying sql driver supported |
This would still let SQL increment/generate the int/long ID's. This would just allow for EF to track which entity should get which ID in the case that multiple entities are added at once. |
This could be useful for identity columns in SQL databases.
Not sure if this should potentially be treated as its own generator, currently just extended the templates for the EF Int and Long converters.
Sample usage when configuring EF Tables