EntityFramework Core HiLo

entity-framework-core

Question

I've read that in Entity Framework Core HiLo pattern "Hi" part is managed by database and "Lo" part is managed by Entity Framework in memory.

How does Entity Framework generate "Lo" part without round-trip to database?

How persist the "Lo" value between requests?

And most important, is this pattern thread safety?

Thanks!

1
1
8/9/2017 12:01:09 PM

Accepted Answer

The HiLo generator works by occasionally reserving a block of IDs on the server then using IDs from that block on the client as needed. You only need to hit the database when reserving the block, so if your block size is 100, you'll round-trip every 100 IDs.

Yes, it's safe to have multiple contexts assigning IDs concurrently since the block is atomically assigned by the database server. Each DbContext instance will have its own block.

2
8/9/2017 4:13:36 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow