Allow a unit of work to request more keys than IdentityBlockSize

2
Voted

Consider a model which has a parent entity with a one-to-many relationship with all of its child entities. If you create a parent then add several new children, then Add the parent to a unit of work, the context will need to allocate keys for the parent and all children. If the number of needed keys is more than the IdentityBlockSize, this will result in more calls to the database than necessary. LightSpeed should instead, in a single update, reserve the smallest multiple of IdentityBlockSize that can accommodate all necessary new keys.

This would make an overloaded Add function useful, which took an IEnumerable<Entity> (or params), so that all given entities could be added such that only a single update to the key table is necessary.

This request comes from a real-life problem I ran into with a slower database connection where simply reserving the necessary keys took over 40 minutes because of all the necessary round-trips. Typical units of work only needed a few dozen keys, but an atypical influx of data required many more. A dynamic IdentityBlockSize would have accomplished the same task of reserving keys in less than a second. A current work-around is to manually determine how many new entities are being added and set IdentityBlockSize, but this becomes non-trivial the larger and more interconnected the model becomes, and all this work is presumably already done by LightSpeed when an entity is added.

Status: New