Explanation of NHibernate HiLo

前端 未结 4 1107
暖寄归人
暖寄归人 2020-12-23 16:50

I\'m struggling to get my head round how the HiLo generator works in NHibernate. I\'ve read the explanation here which made things a little clearer.

My understanding

4条回答
  •  眼角桃花
    2020-12-23 17:49

    Looking at the keys generated by my Nhibernate 3 HiLo objects, the algorithm looks like: (Hi * Lo) + Hi

    So with my Hivalue in the DB as 390 and with my configuration as follows:

    
          
            TableId = 1
            HiValue
            NextValue
            10
          
        
    

    I restart my app pool and get (390 * 10) + 390 = 4290, the range being 4290 - 4300.

    This is the reason why you get seemingly strange gaps in your primary keys because the next generated key from a hi value of 391 is 4301, and the range is 4301 - 4311.

提交回复
热议问题