Explanation of NHibernate HiLo

前端 未结 4 1101
暖寄归人
暖寄归人 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:42

    NHibernate 3.1.1 does this to generate ID using HiLo

    if (lo > maxLo)
    {
        long hival = 
        lo = hival == 0 ? 1 : 0;
        hi = hival * (this.maxLo + 1L);
    }
    long result = hi + lo;
    lo++;
    return result;
    

    Inside NHibernate configuration you specify maxLo. If maxLo is set to 100 you will get 101 ids for each hi value.

提交回复
热议问题