Examples of Entity Framework insert statements generated for different ID creation strategies

Here’s what the generated insert statement SQL looks like in Entity Framework Core (6 Preview 6 in particular) for three different ID creation approaches: HILO, Identity and GUID.

Click on the image for a larger view in a new tab…

For HILO Entity Framework will hit the DB to get the next block of IDs after every X entity inserts (not insert batch). 

EF Core batch inserts using a merge and output statement so the select overhead with IDENTITY is once per batch not once per entity inserted. 

While GUIDS (in this example) are generated completely on the client side so no select overhead at all

Is there performance implications of choosing one approach over the other? Absolutely… and it will likely come down to latency, data volume and perhaps 101 other factors too… BUT… one thing is for sure.. Identity is a solid performer so it’s a great starting point.

Leave a Reply

Your email address will not be published. Required fields are marked *